This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
IronPython Support [WIP] #1250
Open
ihamburglar
wants to merge
8
commits into
EmpireProject:dev
Choose a base branch
from
ihamburglar:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
IronPython Support [WIP] #1250
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cf6bb3e
Modifications of OS enumeration
ihamburglar 5bb3f5a
Modifications of Listener
ihamburglar 06b7a1b
Added IPy dependencies to setup.sh
ihamburglar c339782
Fix typos and add a few things
ihamburglar e601c03
Add IronPython C# stager
ihamburglar 23f13dd
Added remote python https importer
ihamburglar a442db6
Added IronPython C# shell project
ihamburglar c467813
updated httpimport.py to remove unessary code
ihamburglar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#heavily adapated from github.com/operatorequals/httpimport by John Torakis aka operatorequals | ||
''' | ||
Copyright 2017 John Torakis | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
''' | ||
|
||
import imp | ||
import sys | ||
from System.Net import WebClient | ||
|
||
class HttpImporter(object): | ||
def __init__(self, base_url): | ||
self.base_url = base_url | ||
def find_module(self, fullname, path=None): | ||
try: | ||
loader = imp.find_module(fullname, path) | ||
return None | ||
except ImportError: | ||
pass | ||
if fullname.split('.').count(fullname.split('.')[-1]) > 1: | ||
return None | ||
|
||
return self | ||
|
||
def load_module(self, name): | ||
|
||
imp.acquire_lock() | ||
if name in sys.modules: | ||
imp.release_lock() | ||
return sys.modules[name] | ||
|
||
if name.split('.')[-1] in sys.modules: | ||
imp.release_lock() | ||
return sys.modules[name.split('.')[-1]] | ||
|
||
if name in sys.builtin_module_names: | ||
imp.find_module(name) | ||
imp.load_module(name) | ||
imp.release_lock() | ||
return | ||
|
||
name = name.split('.')[-1] | ||
|
||
#TODO: | ||
#Dealing with stuff not actually in iPy | ||
if name == "strop" or name == "_hashlib" or name == "nt" or name == "fcntl" or name == "posix" or name == "org" or name == "termios" or name == "msvcrt" or name == "EasyDialogs" or name == "pwd" or name == "grp": | ||
return | ||
module_url = self.base_url + '%s.py' % name.replace('.', '/') | ||
#TODO: | ||
#Dealing with weird stuff that happens when packages are needed | ||
if name == "aliases" or name == "hex_codec": | ||
module_url = self.base_url + 'encodings/%s.py' % name.replace('.', '/') | ||
if name == "wintypes" or name == "util" or name == "_endian" or name == "ctypes": | ||
module_url = self.base_url + 'ctypes/%s.py' % name.replace('.', '/') | ||
package_url = self.base_url + '%s/__init__.py' % name.replace('.', '/') | ||
final_url = None | ||
final_src = None | ||
|
||
wc = WebClient() | ||
|
||
try: | ||
final_src = wc.DownloadString(module_url) | ||
final_url = module_url | ||
except: | ||
pass | ||
if final_src is None: | ||
try: | ||
final_url = package_url | ||
package_src = wc.DownloadString(package_url) | ||
final_src = package_src | ||
except IOError as e: | ||
module_src = None | ||
imp.release_lock() | ||
return None | ||
|
||
mod = imp.new_module(name) | ||
mod.__loader__ = self | ||
mod.__file__ = final_url | ||
mod.__package__ = name.split('.')[0] | ||
mod.__path__ = ['/'.join(mod.__file__.split('/')[:-1]) + '/'] | ||
sys.modules[name] = mod | ||
exec(final_src, mod.__dict__) | ||
imp.release_lock() | ||
return mod | ||
|
||
|
||
def add_remote_repo(base_url): | ||
importer = HttpImporter(base_url) | ||
sys.meta_path.insert(0, importer) | ||
return importer | ||
|
||
#def add_remote_repo(base_url): | ||
# importer = HttpImporter(modules, base_url) | ||
# sys.meta_path.insert(0, importer) | ||
# return importer | ||
|
||
|
||
for x in sys.builtin_module_names: | ||
__import__(x) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it isn't obvious what is going on here... sometimes imports have dependencies that they try to import in a try, except block. A normal import system handles this fine, but this custom importer doesn't, so I'm essentially blacklisting modules that can't successfully be imported. If someone has a suggestion for how better to do this let me know.