Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions litebox_common_windows/src/loader.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -489,6 +489,21 @@ impl PeParsedFile {
self.image.image_base
}

#[must_use]
pub fn machine(&self) -> u16 {
self.image.machine
}

#[must_use]
pub fn characteristics(&self) -> u16 {
self.image.characteristics
}

#[must_use]
pub fn dll_characteristics(&self) -> u16 {
self.image.dll_characteristics
}

/// Returns whether the image opts into dynamic-base loading.
#[must_use]
pub fn has_dynamic_base(&self) -> bool {
Expand Down
8 changes: 8 additions & 0 deletions litebox_common_windows/src/nt_status.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -159,6 +159,8 @@ impl NtStatus {
0xC0000046 => "STATUS_MUTANT_NOT_OWNED: Mutant not owned",
0xC0000047 => "STATUS_SEMAPHORE_LIMIT_EXCEEDED: Semaphore limit exceeded",
0xC0000048 => "STATUS_PORT_ALREADY_SET: Port already set",
0xC0000049 => "STATUS_SECTION_NOT_IMAGE: Section not image",
0xC000004E => "STATUS_SECTION_PROTECTION: Section protection",
0xC000004F => "STATUS_EAS_NOT_SUPPORTED: EAS not supported",
0xC0000050 => "STATUS_EA_TOO_LARGE: EA too large",
0xC0000056 => "STATUS_DELETE_PENDING: Delete pending",
Expand DownExpand Up@@ -420,6 +422,9 @@ impl NtStatus {
/// STATUS_SECTION_TOO_BIG
pub const SECTION_TOO_BIG: Self = Self::from_raw(0xC0000040);

/// STATUS_SECTION_NOT_IMAGE
pub const SECTION_NOT_IMAGE: Self = Self::from_raw(0xC0000049);

/// STATUS_PORT_CONNECTION_REFUSED
pub const PORT_CONNECTION_REFUSED: Self = Self::from_raw(0xC0000041);

Expand All@@ -435,6 +440,9 @@ impl NtStatus {
/// STATUS_INVALID_PAGE_PROTECTION
pub const INVALID_PAGE_PROTECTION: Self = Self::from_raw(0xC0000045);

/// STATUS_SECTION_PROTECTION
pub const SECTION_PROTECTION: Self = Self::from_raw(0xC000004E);

/// STATUS_MUTANT_NOT_OWNED
pub const MUTANT_NOT_OWNED: Self = Self::from_raw(0xC0000046);

Expand Down
184 changes: 184 additions & 0 deletions litebox_shim_windows/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,6 +38,9 @@ use crate::syscalls::event::{EventHandleObject, EventObject, EventSubsystem};
use crate::syscalls::file::{FileObject, FileObjectSubsystem};
use crate::syscalls::iocp::{IoCompletionHandleObject, IoCompletionSubsystem};
use crate::syscalls::registry::{RegistryKeyObject, RegistryKeySubsystem};
use crate::syscalls::section::{
MapViewOfSectionParameters, SectionHandleObject, SectionObject, SectionSubsystem,
};
use crate::syscalls::symlink::{SymbolicLinkHandleObject, SymbolicLinkSubsystem};
use crate::syscalls::timer::{TimerCreateParameters, TimerHandleObject, TimerSubsystem};
use crate::syscalls::wait_completion_packet::{
Expand DownExpand Up@@ -90,6 +93,10 @@ pub(crate) type WindowsNlsSectionMappings<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<(u32, u32), (usize, usize)>>;
pub(crate) type WindowsVirtualAllocations<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<usize, WindowsVirtualAllocation>>;
pub(crate) type WindowsSectionNamespace<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<String, Weak<SectionObject<Platform>>>>;
pub(crate) type WindowsSectionViews<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<usize, WindowsSectionView<Platform>>>;
pub(crate) type WindowsEventNamespace<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<String, Weak<EventObject<Platform>>>>;
pub(crate) type WindowsDirectoryNamespace<Platform> = DirectoryNamespace<Platform>;
Expand All@@ -103,6 +110,22 @@ pub(crate) struct WindowsVirtualAllocation {
pub(crate) pages: rangemap::RangeMap<usize, syscalls::mm::PageProtection>,
}

pub(crate) struct WindowsSectionView<Platform: ShimPlatform> {
pub(crate) size: usize,
pub(crate) section_offset: usize,
pub(crate) section: Option<Arc<SectionObject<Platform>>>,
}

impl<Platform: ShimPlatform> Clone for WindowsSectionView<Platform> {
fn clone(&self) -> Self {
Self {
size: self.size,
section_offset: self.section_offset,
section: self.section.clone(),
}
}
}

pub type DefaultFS<Platform> = WindowsFS<Platform>;

pub type WindowsFS<Platform> = litebox::fs::layered::FileSystem<
Expand DownExpand Up@@ -343,6 +366,8 @@ impl<Platform: ShimPlatform, FS: ShimFS> WindowsShim<Platform, FS> {
handles: WindowsHandleStore::<Platform>::new(litebox::fd::RawDescriptorStorage::new()),
directory_namespace,
event_namespace: WindowsEventNamespace::<Platform>::new(BTreeMap::new()),
section_namespace: WindowsSectionNamespace::<Platform>::new(BTreeMap::new()),
section_views: WindowsSectionViews::<Platform>::new(BTreeMap::new()),
nls_section_mappings: WindowsNlsSectionMappings::<Platform>::new(BTreeMap::new()),
virtual_allocations: load_info.virtual_allocations,
system_lcid: AtomicU32::new(syscalls::nls::DEFAULT_LOCALE_ID),
Expand DownExpand Up@@ -387,6 +412,8 @@ pub struct Process<Platform: ShimPlatform> {
handles: WindowsHandleStore<Platform>,
directory_namespace: WindowsDirectoryNamespace<Platform>,
event_namespace: WindowsEventNamespace<Platform>,
section_namespace: WindowsSectionNamespace<Platform>,
section_views: WindowsSectionViews<Platform>,
nls_section_mappings: WindowsNlsSectionMappings<Platform>,
virtual_allocations: WindowsVirtualAllocations<Platform>,
system_lcid: AtomicU32,
Expand DownExpand Up@@ -588,6 +615,15 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtOpenSection {
section_handle,
desired_access,
object_attributes,
} => {
let status =
self.sys_nt_open_section(section_handle, desired_access, object_attributes);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQueryDirectoryObject {
directory_handle,
buffer,
Expand DownExpand Up@@ -662,6 +698,50 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateSection {
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
} => {
let status = self.sys_nt_create_section(
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateSectionEx {
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
extended_parameters,
extended_parameter_count,
} => {
let status = self.sys_nt_create_section_ex(
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
extended_parameters,
extended_parameter_count,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateWaitCompletionPacket {
wait_completion_packet_handle,
desired_access,
Expand DownExpand Up@@ -1023,6 +1103,22 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQuerySection {
section_handle,
section_information_class,
section_information,
section_information_length,
return_length,
} => {
let status = self.sys_nt_query_section(
section_handle,
section_information_class,
section_information,
section_information_length,
return_length,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQueryInformationProcess {
process_handle,
process_information_class,
Expand DownExpand Up@@ -1199,6 +1295,80 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtMapViewOfSection {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
} => {
let status = self.sys_nt_map_view_of_section(MapViewOfSectionParameters {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
});
(status, ContinueOperation::Resume)
}
SyscallRequest::NtMapViewOfSectionEx {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
extended_parameters,
extended_parameter_count,
} => {
let status = self.sys_nt_map_view_of_section_ex(
MapViewOfSectionParameters {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
},
extended_parameters,
extended_parameter_count,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtUnmapViewOfSection {
process_handle,
base_address,
} => {
let status = self.sys_nt_unmap_view_of_section(process_handle, base_address);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtUnmapViewOfSectionEx {
process_handle,
base_address,
flags,
} => {
let status =
self.sys_nt_unmap_view_of_section_ex(process_handle, base_address, flags);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtTerminateProcess {
process_handle,
exit_status,
Expand DownExpand Up@@ -1306,6 +1476,14 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
) {
return NtStatus::SUCCESS;
}
if remove_raw_handle_by_raw_fd::<Platform, SectionSubsystem<Platform>>(
&self.global.litebox,
&self.process.handles,
raw_fd,
|section| visitor.section(section),
) {
return NtStatus::SUCCESS;
}
NtStatus::INVALID_HANDLE
}

Expand DownExpand Up@@ -1342,6 +1520,8 @@ trait RawHandleVisitor<Platform: ShimPlatform, FS: ShimFS> {
);

fn worker_factory(&self, worker_factory: WorkerFactoryHandleObject<Platform>);

fn section(&self, section: SectionHandleObject<Platform>);
}

struct CloseRawHandleVisitor<'task, Platform: ShimPlatform, FS: ShimFS> {
Expand DownExpand Up@@ -1389,6 +1569,10 @@ impl<Platform: ShimPlatform, FS: ShimFS> RawHandleVisitor<Platform, FS>
fn worker_factory(&self, worker_factory: WorkerFactoryHandleObject<Platform>) {
Task::<Platform, FS>::close_worker_factory(worker_factory);
}

fn section(&self, section: SectionHandleObject<Platform>) {
Task::<Platform, FS>::close_section(section);
}
}

/// The shim entrypoint object passed to the platform.
Expand Down
1 change: 1 addition & 0 deletions litebox_shim_windows/src/loader/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,3 +4,4 @@
mod pe;

pub(super) use pe::{PeLoader, WindowsLoadError};
pub(crate) use pe::{image_section_metadata, load_image_section};
52 changes: 52 additions & 0 deletions litebox_shim_windows/src/loader/pe.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1224,6 +1224,58 @@ fn load_image<Platform: crate::ShimPlatform, FS: ShimFS>(
load_image_with_writable_sections(fs, path, platform, page_manager, &[])
}

pub(crate) fn load_image_section<Platform: crate::ShimPlatform, FS: ShimFS>(
platform: &'static Platform,
fs: Arc<FS>,
path: &str,
page_manager: &crate::WindowsPageManager<Platform>,
virtual_allocations: &crate::WindowsVirtualAllocations<Platform>,
) -> Result<MappingInfo, WindowsLoadError> {
let image = load_image(platform, fs, path, page_manager)?;
let mapping = image.mapping;
register_image_virtual_allocation(virtual_allocations, mapping, image.pages);
Ok(mapping)
}

pub(crate) struct ImageSectionMetadata {
pub(crate) transfer_address: usize,
pub(crate) file_size: u32,
pub(crate) subsystem: u32,
pub(crate) subsystem_major_version: u16,
pub(crate) subsystem_minor_version: u16,
pub(crate) image_characteristics: u16,
pub(crate) dll_characteristics: u16,
pub(crate) machine: u16,
}

pub(crate) fn image_section_metadata<FS: ShimFS>(
fs: Arc<FS>,
path: &str,
) -> Result<ImageSectionMetadata, WindowsLoadError> {
let file = PeImageFile::open(fs, path)?;
let parsed = PeParsedFile::parse(&mut &file).map_err(WindowsLoadError::Parse)?;
let file_size = file
.fs
.fd_file_status(&file.fd)
.map_err(PeImageAccessError::FileStatus)?
.size
.try_into()
.map_err(|_| PeImageAccessError::AddressOverflow)?;
Ok(ImageSectionMetadata {
transfer_address: parsed
.image_base()
.checked_add(parsed.entry_point_rva())
.ok_or(PeImageAccessError::AddressOverflow)?,
file_size,
subsystem: u32::from(parsed.subsystem()),
subsystem_major_version: parsed.major_subsystem_version(),
subsystem_minor_version: parsed.minor_subsystem_version(),
image_characteristics: parsed.characteristics(),
dll_characteristics: parsed.dll_characteristics(),
machine: parsed.machine(),
})
}

fn load_image_with_writable_sections<Platform: crate::ShimPlatform, FS: ShimFS>(
fs: Arc<FS>,
path: &str,
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions litebox_common_windows/src/loader.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -489,6 +489,21 @@ impl PeParsedFile {
self.image.image_base
}

#[must_use]
pub fn machine(&self) -> u16 {
self.image.machine
}

#[must_use]
pub fn characteristics(&self) -> u16 {
self.image.characteristics
}

#[must_use]
pub fn dll_characteristics(&self) -> u16 {
self.image.dll_characteristics
}

/// Returns whether the image opts into dynamic-base loading.
#[must_use]
pub fn has_dynamic_base(&self) -> bool {
Expand Down
8 changes: 8 additions & 0 deletions litebox_common_windows/src/nt_status.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -159,6 +159,8 @@ impl NtStatus {
0xC0000046 => "STATUS_MUTANT_NOT_OWNED: Mutant not owned",
0xC0000047 => "STATUS_SEMAPHORE_LIMIT_EXCEEDED: Semaphore limit exceeded",
0xC0000048 => "STATUS_PORT_ALREADY_SET: Port already set",
0xC0000049 => "STATUS_SECTION_NOT_IMAGE: Section not image",
0xC000004E => "STATUS_SECTION_PROTECTION: Section protection",
0xC000004F => "STATUS_EAS_NOT_SUPPORTED: EAS not supported",
0xC0000050 => "STATUS_EA_TOO_LARGE: EA too large",
0xC0000056 => "STATUS_DELETE_PENDING: Delete pending",
Expand DownExpand Up@@ -420,6 +422,9 @@ impl NtStatus {
/// STATUS_SECTION_TOO_BIG
pub const SECTION_TOO_BIG: Self = Self::from_raw(0xC0000040);

/// STATUS_SECTION_NOT_IMAGE
pub const SECTION_NOT_IMAGE: Self = Self::from_raw(0xC0000049);

/// STATUS_PORT_CONNECTION_REFUSED
pub const PORT_CONNECTION_REFUSED: Self = Self::from_raw(0xC0000041);

Expand All@@ -435,6 +440,9 @@ impl NtStatus {
/// STATUS_INVALID_PAGE_PROTECTION
pub const INVALID_PAGE_PROTECTION: Self = Self::from_raw(0xC0000045);

/// STATUS_SECTION_PROTECTION
pub const SECTION_PROTECTION: Self = Self::from_raw(0xC000004E);

/// STATUS_MUTANT_NOT_OWNED
pub const MUTANT_NOT_OWNED: Self = Self::from_raw(0xC0000046);

Expand Down
184 changes: 184 additions & 0 deletions litebox_shim_windows/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,6 +38,9 @@ use crate::syscalls::event::{EventHandleObject, EventObject, EventSubsystem};
use crate::syscalls::file::{FileObject, FileObjectSubsystem};
use crate::syscalls::iocp::{IoCompletionHandleObject, IoCompletionSubsystem};
use crate::syscalls::registry::{RegistryKeyObject, RegistryKeySubsystem};
use crate::syscalls::section::{
MapViewOfSectionParameters, SectionHandleObject, SectionObject, SectionSubsystem,
};
use crate::syscalls::symlink::{SymbolicLinkHandleObject, SymbolicLinkSubsystem};
use crate::syscalls::timer::{TimerCreateParameters, TimerHandleObject, TimerSubsystem};
use crate::syscalls::wait_completion_packet::{
Expand DownExpand Up@@ -90,6 +93,10 @@ pub(crate) type WindowsNlsSectionMappings<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<(u32, u32), (usize, usize)>>;
pub(crate) type WindowsVirtualAllocations<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<usize, WindowsVirtualAllocation>>;
pub(crate) type WindowsSectionNamespace<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<String, Weak<SectionObject<Platform>>>>;
pub(crate) type WindowsSectionViews<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<usize, WindowsSectionView<Platform>>>;
pub(crate) type WindowsEventNamespace<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<String, Weak<EventObject<Platform>>>>;
pub(crate) type WindowsDirectoryNamespace<Platform> = DirectoryNamespace<Platform>;
Expand All@@ -103,6 +110,22 @@ pub(crate) struct WindowsVirtualAllocation {
pub(crate) pages: rangemap::RangeMap<usize, syscalls::mm::PageProtection>,
}

pub(crate) struct WindowsSectionView<Platform: ShimPlatform> {
pub(crate) size: usize,
pub(crate) section_offset: usize,
pub(crate) section: Option<Arc<SectionObject<Platform>>>,
}

impl<Platform: ShimPlatform> Clone for WindowsSectionView<Platform> {
fn clone(&self) -> Self {
Self {
size: self.size,
section_offset: self.section_offset,
section: self.section.clone(),
}
}
}

pub type DefaultFS<Platform> = WindowsFS<Platform>;

pub type WindowsFS<Platform> = litebox::fs::layered::FileSystem<
Expand DownExpand Up@@ -343,6 +366,8 @@ impl<Platform: ShimPlatform, FS: ShimFS> WindowsShim<Platform, FS> {
handles: WindowsHandleStore::<Platform>::new(litebox::fd::RawDescriptorStorage::new()),
directory_namespace,
event_namespace: WindowsEventNamespace::<Platform>::new(BTreeMap::new()),
section_namespace: WindowsSectionNamespace::<Platform>::new(BTreeMap::new()),
section_views: WindowsSectionViews::<Platform>::new(BTreeMap::new()),
nls_section_mappings: WindowsNlsSectionMappings::<Platform>::new(BTreeMap::new()),
virtual_allocations: load_info.virtual_allocations,
system_lcid: AtomicU32::new(syscalls::nls::DEFAULT_LOCALE_ID),
Expand DownExpand Up@@ -387,6 +412,8 @@ pub struct Process<Platform: ShimPlatform> {
handles: WindowsHandleStore<Platform>,
directory_namespace: WindowsDirectoryNamespace<Platform>,
event_namespace: WindowsEventNamespace<Platform>,
section_namespace: WindowsSectionNamespace<Platform>,
section_views: WindowsSectionViews<Platform>,
nls_section_mappings: WindowsNlsSectionMappings<Platform>,
virtual_allocations: WindowsVirtualAllocations<Platform>,
system_lcid: AtomicU32,
Expand DownExpand Up@@ -588,6 +615,15 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtOpenSection {
section_handle,
desired_access,
object_attributes,
} => {
let status =
self.sys_nt_open_section(section_handle, desired_access, object_attributes);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQueryDirectoryObject {
directory_handle,
buffer,
Expand DownExpand Up@@ -662,6 +698,50 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateSection {
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
} => {
let status = self.sys_nt_create_section(
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateSectionEx {
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
extended_parameters,
extended_parameter_count,
} => {
let status = self.sys_nt_create_section_ex(
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
extended_parameters,
extended_parameter_count,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateWaitCompletionPacket {
wait_completion_packet_handle,
desired_access,
Expand DownExpand Up@@ -1023,6 +1103,22 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQuerySection {
section_handle,
section_information_class,
section_information,
section_information_length,
return_length,
} => {
let status = self.sys_nt_query_section(
section_handle,
section_information_class,
section_information,
section_information_length,
return_length,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQueryInformationProcess {
process_handle,
process_information_class,
Expand DownExpand Up@@ -1199,6 +1295,80 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtMapViewOfSection {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
} => {
let status = self.sys_nt_map_view_of_section(MapViewOfSectionParameters {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
});
(status, ContinueOperation::Resume)
}
SyscallRequest::NtMapViewOfSectionEx {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
extended_parameters,
extended_parameter_count,
} => {
let status = self.sys_nt_map_view_of_section_ex(
MapViewOfSectionParameters {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
},
extended_parameters,
extended_parameter_count,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtUnmapViewOfSection {
process_handle,
base_address,
} => {
let status = self.sys_nt_unmap_view_of_section(process_handle, base_address);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtUnmapViewOfSectionEx {
process_handle,
base_address,
flags,
} => {
let status =
self.sys_nt_unmap_view_of_section_ex(process_handle, base_address, flags);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtTerminateProcess {
process_handle,
exit_status,
Expand DownExpand Up@@ -1306,6 +1476,14 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
) {
return NtStatus::SUCCESS;
}
if remove_raw_handle_by_raw_fd::<Platform, SectionSubsystem<Platform>>(
&self.global.litebox,
&self.process.handles,
raw_fd,
|section| visitor.section(section),
) {
return NtStatus::SUCCESS;
}
NtStatus::INVALID_HANDLE
}

Expand DownExpand Up@@ -1342,6 +1520,8 @@ trait RawHandleVisitor<Platform: ShimPlatform, FS: ShimFS> {
);

fn worker_factory(&self, worker_factory: WorkerFactoryHandleObject<Platform>);

fn section(&self, section: SectionHandleObject<Platform>);
}

struct CloseRawHandleVisitor<'task, Platform: ShimPlatform, FS: ShimFS> {
Expand DownExpand Up@@ -1389,6 +1569,10 @@ impl<Platform: ShimPlatform, FS: ShimFS> RawHandleVisitor<Platform, FS>
fn worker_factory(&self, worker_factory: WorkerFactoryHandleObject<Platform>) {
Task::<Platform, FS>::close_worker_factory(worker_factory);
}

fn section(&self, section: SectionHandleObject<Platform>) {
Task::<Platform, FS>::close_section(section);
}
}

/// The shim entrypoint object passed to the platform.
Expand Down
1 change: 1 addition & 0 deletions litebox_shim_windows/src/loader/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,3 +4,4 @@
mod pe;

pub(super) use pe::{PeLoader, WindowsLoadError};
pub(crate) use pe::{image_section_metadata, load_image_section};
52 changes: 52 additions & 0 deletions litebox_shim_windows/src/loader/pe.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1224,6 +1224,58 @@ fn load_image<Platform: crate::ShimPlatform, FS: ShimFS>(
load_image_with_writable_sections(fs, path, platform, page_manager, &[])
}

pub(crate) fn load_image_section<Platform: crate::ShimPlatform, FS: ShimFS>(
platform: &'static Platform,
fs: Arc<FS>,
path: &str,
page_manager: &crate::WindowsPageManager<Platform>,
virtual_allocations: &crate::WindowsVirtualAllocations<Platform>,
) -> Result<MappingInfo, WindowsLoadError> {
let image = load_image(platform, fs, path, page_manager)?;
let mapping = image.mapping;
register_image_virtual_allocation(virtual_allocations, mapping, image.pages);
Ok(mapping)
}

pub(crate) struct ImageSectionMetadata {
pub(crate) transfer_address: usize,
pub(crate) file_size: u32,
pub(crate) subsystem: u32,
pub(crate) subsystem_major_version: u16,
pub(crate) subsystem_minor_version: u16,
pub(crate) image_characteristics: u16,
pub(crate) dll_characteristics: u16,
pub(crate) machine: u16,
}

pub(crate) fn image_section_metadata<FS: ShimFS>(
fs: Arc<FS>,
path: &str,
) -> Result<ImageSectionMetadata, WindowsLoadError> {
let file = PeImageFile::open(fs, path)?;
let parsed = PeParsedFile::parse(&mut &file).map_err(WindowsLoadError::Parse)?;
let file_size = file
.fs
.fd_file_status(&file.fd)
.map_err(PeImageAccessError::FileStatus)?
.size
.try_into()
.map_err(|_| PeImageAccessError::AddressOverflow)?;
Ok(ImageSectionMetadata {
transfer_address: parsed
.image_base()
.checked_add(parsed.entry_point_rva())
.ok_or(PeImageAccessError::AddressOverflow)?,
file_size,
subsystem: u32::from(parsed.subsystem()),
subsystem_major_version: parsed.major_subsystem_version(),
subsystem_minor_version: parsed.minor_subsystem_version(),
image_characteristics: parsed.characteristics(),
dll_characteristics: parsed.dll_characteristics(),
machine: parsed.machine(),
})
}

fn load_image_with_writable_sections<Platform: crate::ShimPlatform, FS: ShimFS>(
fs: Arc<FS>,
path: &str,
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions litebox_common_windows/src/loader.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -489,6 +489,21 @@ impl PeParsedFile {
self.image.image_base
}

#[must_use]
pub fn machine(&self) -> u16 {
self.image.machine
}

#[must_use]
pub fn characteristics(&self) -> u16 {
self.image.characteristics
}

#[must_use]
pub fn dll_characteristics(&self) -> u16 {
self.image.dll_characteristics
}

/// Returns whether the image opts into dynamic-base loading.
#[must_use]
pub fn has_dynamic_base(&self) -> bool {
Expand Down
8 changes: 8 additions & 0 deletions litebox_common_windows/src/nt_status.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -159,6 +159,8 @@ impl NtStatus {
0xC0000046 => "STATUS_MUTANT_NOT_OWNED: Mutant not owned",
0xC0000047 => "STATUS_SEMAPHORE_LIMIT_EXCEEDED: Semaphore limit exceeded",
0xC0000048 => "STATUS_PORT_ALREADY_SET: Port already set",
0xC0000049 => "STATUS_SECTION_NOT_IMAGE: Section not image",
0xC000004E => "STATUS_SECTION_PROTECTION: Section protection",
0xC000004F => "STATUS_EAS_NOT_SUPPORTED: EAS not supported",
0xC0000050 => "STATUS_EA_TOO_LARGE: EA too large",
0xC0000056 => "STATUS_DELETE_PENDING: Delete pending",
Expand DownExpand Up@@ -420,6 +422,9 @@ impl NtStatus {
/// STATUS_SECTION_TOO_BIG
pub const SECTION_TOO_BIG: Self = Self::from_raw(0xC0000040);

/// STATUS_SECTION_NOT_IMAGE
pub const SECTION_NOT_IMAGE: Self = Self::from_raw(0xC0000049);

/// STATUS_PORT_CONNECTION_REFUSED
pub const PORT_CONNECTION_REFUSED: Self = Self::from_raw(0xC0000041);

Expand All@@ -435,6 +440,9 @@ impl NtStatus {
/// STATUS_INVALID_PAGE_PROTECTION
pub const INVALID_PAGE_PROTECTION: Self = Self::from_raw(0xC0000045);

/// STATUS_SECTION_PROTECTION
pub const SECTION_PROTECTION: Self = Self::from_raw(0xC000004E);

/// STATUS_MUTANT_NOT_OWNED
pub const MUTANT_NOT_OWNED: Self = Self::from_raw(0xC0000046);

Expand Down
184 changes: 184 additions & 0 deletions litebox_shim_windows/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,6 +38,9 @@ use crate::syscalls::event::{EventHandleObject, EventObject, EventSubsystem};
use crate::syscalls::file::{FileObject, FileObjectSubsystem};
use crate::syscalls::iocp::{IoCompletionHandleObject, IoCompletionSubsystem};
use crate::syscalls::registry::{RegistryKeyObject, RegistryKeySubsystem};
use crate::syscalls::section::{
MapViewOfSectionParameters, SectionHandleObject, SectionObject, SectionSubsystem,
};
use crate::syscalls::symlink::{SymbolicLinkHandleObject, SymbolicLinkSubsystem};
use crate::syscalls::timer::{TimerCreateParameters, TimerHandleObject, TimerSubsystem};
use crate::syscalls::wait_completion_packet::{
Expand DownExpand Up@@ -90,6 +93,10 @@ pub(crate) type WindowsNlsSectionMappings<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<(u32, u32), (usize, usize)>>;
pub(crate) type WindowsVirtualAllocations<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<usize, WindowsVirtualAllocation>>;
pub(crate) type WindowsSectionNamespace<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<String, Weak<SectionObject<Platform>>>>;
pub(crate) type WindowsSectionViews<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<usize, WindowsSectionView<Platform>>>;
pub(crate) type WindowsEventNamespace<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<String, Weak<EventObject<Platform>>>>;
pub(crate) type WindowsDirectoryNamespace<Platform> = DirectoryNamespace<Platform>;
Expand All@@ -103,6 +110,22 @@ pub(crate) struct WindowsVirtualAllocation {
pub(crate) pages: rangemap::RangeMap<usize, syscalls::mm::PageProtection>,
}

pub(crate) struct WindowsSectionView<Platform: ShimPlatform> {
pub(crate) size: usize,
pub(crate) section_offset: usize,
pub(crate) section: Option<Arc<SectionObject<Platform>>>,
}

impl<Platform: ShimPlatform> Clone for WindowsSectionView<Platform> {
fn clone(&self) -> Self {
Self {
size: self.size,
section_offset: self.section_offset,
section: self.section.clone(),
}
}
}

pub type DefaultFS<Platform> = WindowsFS<Platform>;

pub type WindowsFS<Platform> = litebox::fs::layered::FileSystem<
Expand DownExpand Up@@ -343,6 +366,8 @@ impl<Platform: ShimPlatform, FS: ShimFS> WindowsShim<Platform, FS> {
handles: WindowsHandleStore::<Platform>::new(litebox::fd::RawDescriptorStorage::new()),
directory_namespace,
event_namespace: WindowsEventNamespace::<Platform>::new(BTreeMap::new()),
section_namespace: WindowsSectionNamespace::<Platform>::new(BTreeMap::new()),
section_views: WindowsSectionViews::<Platform>::new(BTreeMap::new()),
nls_section_mappings: WindowsNlsSectionMappings::<Platform>::new(BTreeMap::new()),
virtual_allocations: load_info.virtual_allocations,
system_lcid: AtomicU32::new(syscalls::nls::DEFAULT_LOCALE_ID),
Expand DownExpand Up@@ -387,6 +412,8 @@ pub struct Process<Platform: ShimPlatform> {
handles: WindowsHandleStore<Platform>,
directory_namespace: WindowsDirectoryNamespace<Platform>,
event_namespace: WindowsEventNamespace<Platform>,
section_namespace: WindowsSectionNamespace<Platform>,
section_views: WindowsSectionViews<Platform>,
nls_section_mappings: WindowsNlsSectionMappings<Platform>,
virtual_allocations: WindowsVirtualAllocations<Platform>,
system_lcid: AtomicU32,
Expand DownExpand Up@@ -588,6 +615,15 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtOpenSection {
section_handle,
desired_access,
object_attributes,
} => {
let status =
self.sys_nt_open_section(section_handle, desired_access, object_attributes);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQueryDirectoryObject {
directory_handle,
buffer,
Expand DownExpand Up@@ -662,6 +698,50 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateSection {
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
} => {
let status = self.sys_nt_create_section(
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateSectionEx {
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
extended_parameters,
extended_parameter_count,
} => {
let status = self.sys_nt_create_section_ex(
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
extended_parameters,
extended_parameter_count,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateWaitCompletionPacket {
wait_completion_packet_handle,
desired_access,
Expand DownExpand Up@@ -1023,6 +1103,22 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQuerySection {
section_handle,
section_information_class,
section_information,
section_information_length,
return_length,
} => {
let status = self.sys_nt_query_section(
section_handle,
section_information_class,
section_information,
section_information_length,
return_length,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQueryInformationProcess {
process_handle,
process_information_class,
Expand DownExpand Up@@ -1199,6 +1295,80 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtMapViewOfSection {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
} => {
let status = self.sys_nt_map_view_of_section(MapViewOfSectionParameters {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
});
(status, ContinueOperation::Resume)
}
SyscallRequest::NtMapViewOfSectionEx {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
extended_parameters,
extended_parameter_count,
} => {
let status = self.sys_nt_map_view_of_section_ex(
MapViewOfSectionParameters {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
},
extended_parameters,
extended_parameter_count,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtUnmapViewOfSection {
process_handle,
base_address,
} => {
let status = self.sys_nt_unmap_view_of_section(process_handle, base_address);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtUnmapViewOfSectionEx {
process_handle,
base_address,
flags,
} => {
let status =
self.sys_nt_unmap_view_of_section_ex(process_handle, base_address, flags);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtTerminateProcess {
process_handle,
exit_status,
Expand DownExpand Up@@ -1306,6 +1476,14 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
) {
return NtStatus::SUCCESS;
}
if remove_raw_handle_by_raw_fd::<Platform, SectionSubsystem<Platform>>(
&self.global.litebox,
&self.process.handles,
raw_fd,
|section| visitor.section(section),
) {
return NtStatus::SUCCESS;
}
NtStatus::INVALID_HANDLE
}

Expand DownExpand Up@@ -1342,6 +1520,8 @@ trait RawHandleVisitor<Platform: ShimPlatform, FS: ShimFS> {
);

fn worker_factory(&self, worker_factory: WorkerFactoryHandleObject<Platform>);

fn section(&self, section: SectionHandleObject<Platform>);
}

struct CloseRawHandleVisitor<'task, Platform: ShimPlatform, FS: ShimFS> {
Expand DownExpand Up@@ -1389,6 +1569,10 @@ impl<Platform: ShimPlatform, FS: ShimFS> RawHandleVisitor<Platform, FS>
fn worker_factory(&self, worker_factory: WorkerFactoryHandleObject<Platform>) {
Task::<Platform, FS>::close_worker_factory(worker_factory);
}

fn section(&self, section: SectionHandleObject<Platform>) {
Task::<Platform, FS>::close_section(section);
}
}

/// The shim entrypoint object passed to the platform.
Expand Down
1 change: 1 addition & 0 deletions litebox_shim_windows/src/loader/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,3 +4,4 @@
mod pe;

pub(super) use pe::{PeLoader, WindowsLoadError};
pub(crate) use pe::{image_section_metadata, load_image_section};
52 changes: 52 additions & 0 deletions litebox_shim_windows/src/loader/pe.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1224,6 +1224,58 @@ fn load_image<Platform: crate::ShimPlatform, FS: ShimFS>(
load_image_with_writable_sections(fs, path, platform, page_manager, &[])
}

pub(crate) fn load_image_section<Platform: crate::ShimPlatform, FS: ShimFS>(
platform: &'static Platform,
fs: Arc<FS>,
path: &str,
page_manager: &crate::WindowsPageManager<Platform>,
virtual_allocations: &crate::WindowsVirtualAllocations<Platform>,
) -> Result<MappingInfo, WindowsLoadError> {
let image = load_image(platform, fs, path, page_manager)?;
let mapping = image.mapping;
register_image_virtual_allocation(virtual_allocations, mapping, image.pages);
Ok(mapping)
}

pub(crate) struct ImageSectionMetadata {
pub(crate) transfer_address: usize,
pub(crate) file_size: u32,
pub(crate) subsystem: u32,
pub(crate) subsystem_major_version: u16,
pub(crate) subsystem_minor_version: u16,
pub(crate) image_characteristics: u16,
pub(crate) dll_characteristics: u16,
pub(crate) machine: u16,
}

pub(crate) fn image_section_metadata<FS: ShimFS>(
fs: Arc<FS>,
path: &str,
) -> Result<ImageSectionMetadata, WindowsLoadError> {
let file = PeImageFile::open(fs, path)?;
let parsed = PeParsedFile::parse(&mut &file).map_err(WindowsLoadError::Parse)?;
let file_size = file
.fs
.fd_file_status(&file.fd)
.map_err(PeImageAccessError::FileStatus)?
.size
.try_into()
.map_err(|_| PeImageAccessError::AddressOverflow)?;
Ok(ImageSectionMetadata {
transfer_address: parsed
.image_base()
.checked_add(parsed.entry_point_rva())
.ok_or(PeImageAccessError::AddressOverflow)?,
file_size,
subsystem: u32::from(parsed.subsystem()),
subsystem_major_version: parsed.major_subsystem_version(),
subsystem_minor_version: parsed.minor_subsystem_version(),
image_characteristics: parsed.characteristics(),
dll_characteristics: parsed.dll_characteristics(),
machine: parsed.machine(),
})
}

fn load_image_with_writable_sections<Platform: crate::ShimPlatform, FS: ShimFS>(
fs: Arc<FS>,
path: &str,
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions litebox_common_windows/src/loader.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -489,6 +489,21 @@ impl PeParsedFile {
self.image.image_base
}

#[must_use]
pub fn machine(&self) -> u16 {
self.image.machine
}

#[must_use]
pub fn characteristics(&self) -> u16 {
self.image.characteristics
}

#[must_use]
pub fn dll_characteristics(&self) -> u16 {
self.image.dll_characteristics
}

/// Returns whether the image opts into dynamic-base loading.
#[must_use]
pub fn has_dynamic_base(&self) -> bool {
Expand Down
8 changes: 8 additions & 0 deletions litebox_common_windows/src/nt_status.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -159,6 +159,8 @@ impl NtStatus {
0xC0000046 => "STATUS_MUTANT_NOT_OWNED: Mutant not owned",
0xC0000047 => "STATUS_SEMAPHORE_LIMIT_EXCEEDED: Semaphore limit exceeded",
0xC0000048 => "STATUS_PORT_ALREADY_SET: Port already set",
0xC0000049 => "STATUS_SECTION_NOT_IMAGE: Section not image",
0xC000004E => "STATUS_SECTION_PROTECTION: Section protection",
0xC000004F => "STATUS_EAS_NOT_SUPPORTED: EAS not supported",
0xC0000050 => "STATUS_EA_TOO_LARGE: EA too large",
0xC0000056 => "STATUS_DELETE_PENDING: Delete pending",
Expand DownExpand Up@@ -420,6 +422,9 @@ impl NtStatus {
/// STATUS_SECTION_TOO_BIG
pub const SECTION_TOO_BIG: Self = Self::from_raw(0xC0000040);

/// STATUS_SECTION_NOT_IMAGE
pub const SECTION_NOT_IMAGE: Self = Self::from_raw(0xC0000049);

/// STATUS_PORT_CONNECTION_REFUSED
pub const PORT_CONNECTION_REFUSED: Self = Self::from_raw(0xC0000041);

Expand All@@ -435,6 +440,9 @@ impl NtStatus {
/// STATUS_INVALID_PAGE_PROTECTION
pub const INVALID_PAGE_PROTECTION: Self = Self::from_raw(0xC0000045);

/// STATUS_SECTION_PROTECTION
pub const SECTION_PROTECTION: Self = Self::from_raw(0xC000004E);

/// STATUS_MUTANT_NOT_OWNED
pub const MUTANT_NOT_OWNED: Self = Self::from_raw(0xC0000046);

Expand Down
184 changes: 184 additions & 0 deletions litebox_shim_windows/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,6 +38,9 @@ use crate::syscalls::event::{EventHandleObject, EventObject, EventSubsystem};
use crate::syscalls::file::{FileObject, FileObjectSubsystem};
use crate::syscalls::iocp::{IoCompletionHandleObject, IoCompletionSubsystem};
use crate::syscalls::registry::{RegistryKeyObject, RegistryKeySubsystem};
use crate::syscalls::section::{
MapViewOfSectionParameters, SectionHandleObject, SectionObject, SectionSubsystem,
};
use crate::syscalls::symlink::{SymbolicLinkHandleObject, SymbolicLinkSubsystem};
use crate::syscalls::timer::{TimerCreateParameters, TimerHandleObject, TimerSubsystem};
use crate::syscalls::wait_completion_packet::{
Expand DownExpand Up@@ -90,6 +93,10 @@ pub(crate) type WindowsNlsSectionMappings<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<(u32, u32), (usize, usize)>>;
pub(crate) type WindowsVirtualAllocations<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<usize, WindowsVirtualAllocation>>;
pub(crate) type WindowsSectionNamespace<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<String, Weak<SectionObject<Platform>>>>;
pub(crate) type WindowsSectionViews<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<usize, WindowsSectionView<Platform>>>;
pub(crate) type WindowsEventNamespace<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<String, Weak<EventObject<Platform>>>>;
pub(crate) type WindowsDirectoryNamespace<Platform> = DirectoryNamespace<Platform>;
Expand All@@ -103,6 +110,22 @@ pub(crate) struct WindowsVirtualAllocation {
pub(crate) pages: rangemap::RangeMap<usize, syscalls::mm::PageProtection>,
}

pub(crate) struct WindowsSectionView<Platform: ShimPlatform> {
pub(crate) size: usize,
pub(crate) section_offset: usize,
pub(crate) section: Option<Arc<SectionObject<Platform>>>,
}

impl<Platform: ShimPlatform> Clone for WindowsSectionView<Platform> {
fn clone(&self) -> Self {
Self {
size: self.size,
section_offset: self.section_offset,
section: self.section.clone(),
}
}
}

pub type DefaultFS<Platform> = WindowsFS<Platform>;

pub type WindowsFS<Platform> = litebox::fs::layered::FileSystem<
Expand DownExpand Up@@ -343,6 +366,8 @@ impl<Platform: ShimPlatform, FS: ShimFS> WindowsShim<Platform, FS> {
handles: WindowsHandleStore::<Platform>::new(litebox::fd::RawDescriptorStorage::new()),
directory_namespace,
event_namespace: WindowsEventNamespace::<Platform>::new(BTreeMap::new()),
section_namespace: WindowsSectionNamespace::<Platform>::new(BTreeMap::new()),
section_views: WindowsSectionViews::<Platform>::new(BTreeMap::new()),
nls_section_mappings: WindowsNlsSectionMappings::<Platform>::new(BTreeMap::new()),
virtual_allocations: load_info.virtual_allocations,
system_lcid: AtomicU32::new(syscalls::nls::DEFAULT_LOCALE_ID),
Expand DownExpand Up@@ -387,6 +412,8 @@ pub struct Process<Platform: ShimPlatform> {
handles: WindowsHandleStore<Platform>,
directory_namespace: WindowsDirectoryNamespace<Platform>,
event_namespace: WindowsEventNamespace<Platform>,
section_namespace: WindowsSectionNamespace<Platform>,
section_views: WindowsSectionViews<Platform>,
nls_section_mappings: WindowsNlsSectionMappings<Platform>,
virtual_allocations: WindowsVirtualAllocations<Platform>,
system_lcid: AtomicU32,
Expand DownExpand Up@@ -588,6 +615,15 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtOpenSection {
section_handle,
desired_access,
object_attributes,
} => {
let status =
self.sys_nt_open_section(section_handle, desired_access, object_attributes);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQueryDirectoryObject {
directory_handle,
buffer,
Expand DownExpand Up@@ -662,6 +698,50 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateSection {
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
} => {
let status = self.sys_nt_create_section(
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateSectionEx {
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
extended_parameters,
extended_parameter_count,
} => {
let status = self.sys_nt_create_section_ex(
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
extended_parameters,
extended_parameter_count,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateWaitCompletionPacket {
wait_completion_packet_handle,
desired_access,
Expand DownExpand Up@@ -1023,6 +1103,22 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQuerySection {
section_handle,
section_information_class,
section_information,
section_information_length,
return_length,
} => {
let status = self.sys_nt_query_section(
section_handle,
section_information_class,
section_information,
section_information_length,
return_length,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQueryInformationProcess {
process_handle,
process_information_class,
Expand DownExpand Up@@ -1199,6 +1295,80 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtMapViewOfSection {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
} => {
let status = self.sys_nt_map_view_of_section(MapViewOfSectionParameters {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
});
(status, ContinueOperation::Resume)
}
SyscallRequest::NtMapViewOfSectionEx {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
extended_parameters,
extended_parameter_count,
} => {
let status = self.sys_nt_map_view_of_section_ex(
MapViewOfSectionParameters {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
},
extended_parameters,
extended_parameter_count,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtUnmapViewOfSection {
process_handle,
base_address,
} => {
let status = self.sys_nt_unmap_view_of_section(process_handle, base_address);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtUnmapViewOfSectionEx {
process_handle,
base_address,
flags,
} => {
let status =
self.sys_nt_unmap_view_of_section_ex(process_handle, base_address, flags);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtTerminateProcess {
process_handle,
exit_status,
Expand DownExpand Up@@ -1306,6 +1476,14 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
) {
return NtStatus::SUCCESS;
}
if remove_raw_handle_by_raw_fd::<Platform, SectionSubsystem<Platform>>(
&self.global.litebox,
&self.process.handles,
raw_fd,
|section| visitor.section(section),
) {
return NtStatus::SUCCESS;
}
NtStatus::INVALID_HANDLE
}

Expand DownExpand Up@@ -1342,6 +1520,8 @@ trait RawHandleVisitor<Platform: ShimPlatform, FS: ShimFS> {
);

fn worker_factory(&self, worker_factory: WorkerFactoryHandleObject<Platform>);

fn section(&self, section: SectionHandleObject<Platform>);
}

struct CloseRawHandleVisitor<'task, Platform: ShimPlatform, FS: ShimFS> {
Expand DownExpand Up@@ -1389,6 +1569,10 @@ impl<Platform: ShimPlatform, FS: ShimFS> RawHandleVisitor<Platform, FS>
fn worker_factory(&self, worker_factory: WorkerFactoryHandleObject<Platform>) {
Task::<Platform, FS>::close_worker_factory(worker_factory);
}

fn section(&self, section: SectionHandleObject<Platform>) {
Task::<Platform, FS>::close_section(section);
}
}

/// The shim entrypoint object passed to the platform.
Expand Down
1 change: 1 addition & 0 deletions litebox_shim_windows/src/loader/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,3 +4,4 @@
mod pe;

pub(super) use pe::{PeLoader, WindowsLoadError};
pub(crate) use pe::{image_section_metadata, load_image_section};
52 changes: 52 additions & 0 deletions litebox_shim_windows/src/loader/pe.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1224,6 +1224,58 @@ fn load_image<Platform: crate::ShimPlatform, FS: ShimFS>(
load_image_with_writable_sections(fs, path, platform, page_manager, &[])
}

pub(crate) fn load_image_section<Platform: crate::ShimPlatform, FS: ShimFS>(
platform: &'static Platform,
fs: Arc<FS>,
path: &str,
page_manager: &crate::WindowsPageManager<Platform>,
virtual_allocations: &crate::WindowsVirtualAllocations<Platform>,
) -> Result<MappingInfo, WindowsLoadError> {
let image = load_image(platform, fs, path, page_manager)?;
let mapping = image.mapping;
register_image_virtual_allocation(virtual_allocations, mapping, image.pages);
Ok(mapping)
}

pub(crate) struct ImageSectionMetadata {
pub(crate) transfer_address: usize,
pub(crate) file_size: u32,
pub(crate) subsystem: u32,
pub(crate) subsystem_major_version: u16,
pub(crate) subsystem_minor_version: u16,
pub(crate) image_characteristics: u16,
pub(crate) dll_characteristics: u16,
pub(crate) machine: u16,
}

pub(crate) fn image_section_metadata<FS: ShimFS>(
fs: Arc<FS>,
path: &str,
) -> Result<ImageSectionMetadata, WindowsLoadError> {
let file = PeImageFile::open(fs, path)?;
let parsed = PeParsedFile::parse(&mut &file).map_err(WindowsLoadError::Parse)?;
let file_size = file
.fs
.fd_file_status(&file.fd)
.map_err(PeImageAccessError::FileStatus)?
.size
.try_into()
.map_err(|_| PeImageAccessError::AddressOverflow)?;
Ok(ImageSectionMetadata {
transfer_address: parsed
.image_base()
.checked_add(parsed.entry_point_rva())
.ok_or(PeImageAccessError::AddressOverflow)?,
file_size,
subsystem: u32::from(parsed.subsystem()),
subsystem_major_version: parsed.major_subsystem_version(),
subsystem_minor_version: parsed.minor_subsystem_version(),
image_characteristics: parsed.characteristics(),
dll_characteristics: parsed.dll_characteristics(),
machine: parsed.machine(),
})
}

fn load_image_with_writable_sections<Platform: crate::ShimPlatform, FS: ShimFS>(
fs: Arc<FS>,
path: &str,
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions litebox_common_windows/src/loader.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -489,6 +489,21 @@ impl PeParsedFile {
self.image.image_base
}

#[must_use]
pub fn machine(&self) -> u16 {
self.image.machine
}

#[must_use]
pub fn characteristics(&self) -> u16 {
self.image.characteristics
}

#[must_use]
pub fn dll_characteristics(&self) -> u16 {
self.image.dll_characteristics
}

/// Returns whether the image opts into dynamic-base loading.
#[must_use]
pub fn has_dynamic_base(&self) -> bool {
Expand Down
8 changes: 8 additions & 0 deletions litebox_common_windows/src/nt_status.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -159,6 +159,8 @@ impl NtStatus {
0xC0000046 => "STATUS_MUTANT_NOT_OWNED: Mutant not owned",
0xC0000047 => "STATUS_SEMAPHORE_LIMIT_EXCEEDED: Semaphore limit exceeded",
0xC0000048 => "STATUS_PORT_ALREADY_SET: Port already set",
0xC0000049 => "STATUS_SECTION_NOT_IMAGE: Section not image",
0xC000004E => "STATUS_SECTION_PROTECTION: Section protection",
0xC000004F => "STATUS_EAS_NOT_SUPPORTED: EAS not supported",
0xC0000050 => "STATUS_EA_TOO_LARGE: EA too large",
0xC0000056 => "STATUS_DELETE_PENDING: Delete pending",
Expand DownExpand Up@@ -420,6 +422,9 @@ impl NtStatus {
/// STATUS_SECTION_TOO_BIG
pub const SECTION_TOO_BIG: Self = Self::from_raw(0xC0000040);

/// STATUS_SECTION_NOT_IMAGE
pub const SECTION_NOT_IMAGE: Self = Self::from_raw(0xC0000049);

/// STATUS_PORT_CONNECTION_REFUSED
pub const PORT_CONNECTION_REFUSED: Self = Self::from_raw(0xC0000041);

Expand All@@ -435,6 +440,9 @@ impl NtStatus {
/// STATUS_INVALID_PAGE_PROTECTION
pub const INVALID_PAGE_PROTECTION: Self = Self::from_raw(0xC0000045);

/// STATUS_SECTION_PROTECTION
pub const SECTION_PROTECTION: Self = Self::from_raw(0xC000004E);

/// STATUS_MUTANT_NOT_OWNED
pub const MUTANT_NOT_OWNED: Self = Self::from_raw(0xC0000046);

Expand Down
184 changes: 184 additions & 0 deletions litebox_shim_windows/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,6 +38,9 @@ use crate::syscalls::event::{EventHandleObject, EventObject, EventSubsystem};
use crate::syscalls::file::{FileObject, FileObjectSubsystem};
use crate::syscalls::iocp::{IoCompletionHandleObject, IoCompletionSubsystem};
use crate::syscalls::registry::{RegistryKeyObject, RegistryKeySubsystem};
use crate::syscalls::section::{
MapViewOfSectionParameters, SectionHandleObject, SectionObject, SectionSubsystem,
};
use crate::syscalls::symlink::{SymbolicLinkHandleObject, SymbolicLinkSubsystem};
use crate::syscalls::timer::{TimerCreateParameters, TimerHandleObject, TimerSubsystem};
use crate::syscalls::wait_completion_packet::{
Expand DownExpand Up@@ -90,6 +93,10 @@ pub(crate) type WindowsNlsSectionMappings<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<(u32, u32), (usize, usize)>>;
pub(crate) type WindowsVirtualAllocations<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<usize, WindowsVirtualAllocation>>;
pub(crate) type WindowsSectionNamespace<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<String, Weak<SectionObject<Platform>>>>;
pub(crate) type WindowsSectionViews<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<usize, WindowsSectionView<Platform>>>;
pub(crate) type WindowsEventNamespace<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<String, Weak<EventObject<Platform>>>>;
pub(crate) type WindowsDirectoryNamespace<Platform> = DirectoryNamespace<Platform>;
Expand All@@ -103,6 +110,22 @@ pub(crate) struct WindowsVirtualAllocation {
pub(crate) pages: rangemap::RangeMap<usize, syscalls::mm::PageProtection>,
}

pub(crate) struct WindowsSectionView<Platform: ShimPlatform> {
pub(crate) size: usize,
pub(crate) section_offset: usize,
pub(crate) section: Option<Arc<SectionObject<Platform>>>,
}

impl<Platform: ShimPlatform> Clone for WindowsSectionView<Platform> {
fn clone(&self) -> Self {
Self {
size: self.size,
section_offset: self.section_offset,
section: self.section.clone(),
}
}
}

pub type DefaultFS<Platform> = WindowsFS<Platform>;

pub type WindowsFS<Platform> = litebox::fs::layered::FileSystem<
Expand DownExpand Up@@ -343,6 +366,8 @@ impl<Platform: ShimPlatform, FS: ShimFS> WindowsShim<Platform, FS> {
handles: WindowsHandleStore::<Platform>::new(litebox::fd::RawDescriptorStorage::new()),
directory_namespace,
event_namespace: WindowsEventNamespace::<Platform>::new(BTreeMap::new()),
section_namespace: WindowsSectionNamespace::<Platform>::new(BTreeMap::new()),
section_views: WindowsSectionViews::<Platform>::new(BTreeMap::new()),
nls_section_mappings: WindowsNlsSectionMappings::<Platform>::new(BTreeMap::new()),
virtual_allocations: load_info.virtual_allocations,
system_lcid: AtomicU32::new(syscalls::nls::DEFAULT_LOCALE_ID),
Expand DownExpand Up@@ -387,6 +412,8 @@ pub struct Process<Platform: ShimPlatform> {
handles: WindowsHandleStore<Platform>,
directory_namespace: WindowsDirectoryNamespace<Platform>,
event_namespace: WindowsEventNamespace<Platform>,
section_namespace: WindowsSectionNamespace<Platform>,
section_views: WindowsSectionViews<Platform>,
nls_section_mappings: WindowsNlsSectionMappings<Platform>,
virtual_allocations: WindowsVirtualAllocations<Platform>,
system_lcid: AtomicU32,
Expand DownExpand Up@@ -588,6 +615,15 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtOpenSection {
section_handle,
desired_access,
object_attributes,
} => {
let status =
self.sys_nt_open_section(section_handle, desired_access, object_attributes);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQueryDirectoryObject {
directory_handle,
buffer,
Expand DownExpand Up@@ -662,6 +698,50 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateSection {
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
} => {
let status = self.sys_nt_create_section(
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateSectionEx {
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
extended_parameters,
extended_parameter_count,
} => {
let status = self.sys_nt_create_section_ex(
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
extended_parameters,
extended_parameter_count,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateWaitCompletionPacket {
wait_completion_packet_handle,
desired_access,
Expand DownExpand Up@@ -1023,6 +1103,22 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQuerySection {
section_handle,
section_information_class,
section_information,
section_information_length,
return_length,
} => {
let status = self.sys_nt_query_section(
section_handle,
section_information_class,
section_information,
section_information_length,
return_length,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQueryInformationProcess {
process_handle,
process_information_class,
Expand DownExpand Up@@ -1199,6 +1295,80 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtMapViewOfSection {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
} => {
let status = self.sys_nt_map_view_of_section(MapViewOfSectionParameters {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
});
(status, ContinueOperation::Resume)
}
SyscallRequest::NtMapViewOfSectionEx {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
extended_parameters,
extended_parameter_count,
} => {
let status = self.sys_nt_map_view_of_section_ex(
MapViewOfSectionParameters {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
},
extended_parameters,
extended_parameter_count,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtUnmapViewOfSection {
process_handle,
base_address,
} => {
let status = self.sys_nt_unmap_view_of_section(process_handle, base_address);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtUnmapViewOfSectionEx {
process_handle,
base_address,
flags,
} => {
let status =
self.sys_nt_unmap_view_of_section_ex(process_handle, base_address, flags);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtTerminateProcess {
process_handle,
exit_status,
Expand DownExpand Up@@ -1306,6 +1476,14 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
) {
return NtStatus::SUCCESS;
}
if remove_raw_handle_by_raw_fd::<Platform, SectionSubsystem<Platform>>(
&self.global.litebox,
&self.process.handles,
raw_fd,
|section| visitor.section(section),
) {
return NtStatus::SUCCESS;
}
NtStatus::INVALID_HANDLE
}

Expand DownExpand Up@@ -1342,6 +1520,8 @@ trait RawHandleVisitor<Platform: ShimPlatform, FS: ShimFS> {
);

fn worker_factory(&self, worker_factory: WorkerFactoryHandleObject<Platform>);

fn section(&self, section: SectionHandleObject<Platform>);
}

struct CloseRawHandleVisitor<'task, Platform: ShimPlatform, FS: ShimFS> {
Expand DownExpand Up@@ -1389,6 +1569,10 @@ impl<Platform: ShimPlatform, FS: ShimFS> RawHandleVisitor<Platform, FS>
fn worker_factory(&self, worker_factory: WorkerFactoryHandleObject<Platform>) {
Task::<Platform, FS>::close_worker_factory(worker_factory);
}

fn section(&self, section: SectionHandleObject<Platform>) {
Task::<Platform, FS>::close_section(section);
}
}

/// The shim entrypoint object passed to the platform.
Expand Down
1 change: 1 addition & 0 deletions litebox_shim_windows/src/loader/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,3 +4,4 @@
mod pe;

pub(super) use pe::{PeLoader, WindowsLoadError};
pub(crate) use pe::{image_section_metadata, load_image_section};
52 changes: 52 additions & 0 deletions litebox_shim_windows/src/loader/pe.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1224,6 +1224,58 @@ fn load_image<Platform: crate::ShimPlatform, FS: ShimFS>(
load_image_with_writable_sections(fs, path, platform, page_manager, &[])
}

pub(crate) fn load_image_section<Platform: crate::ShimPlatform, FS: ShimFS>(
platform: &'static Platform,
fs: Arc<FS>,
path: &str,
page_manager: &crate::WindowsPageManager<Platform>,
virtual_allocations: &crate::WindowsVirtualAllocations<Platform>,
) -> Result<MappingInfo, WindowsLoadError> {
let image = load_image(platform, fs, path, page_manager)?;
let mapping = image.mapping;
register_image_virtual_allocation(virtual_allocations, mapping, image.pages);
Ok(mapping)
}

pub(crate) struct ImageSectionMetadata {
pub(crate) transfer_address: usize,
pub(crate) file_size: u32,
pub(crate) subsystem: u32,
pub(crate) subsystem_major_version: u16,
pub(crate) subsystem_minor_version: u16,
pub(crate) image_characteristics: u16,
pub(crate) dll_characteristics: u16,
pub(crate) machine: u16,
}

pub(crate) fn image_section_metadata<FS: ShimFS>(
fs: Arc<FS>,
path: &str,
) -> Result<ImageSectionMetadata, WindowsLoadError> {
let file = PeImageFile::open(fs, path)?;
let parsed = PeParsedFile::parse(&mut &file).map_err(WindowsLoadError::Parse)?;
let file_size = file
.fs
.fd_file_status(&file.fd)
.map_err(PeImageAccessError::FileStatus)?
.size
.try_into()
.map_err(|_| PeImageAccessError::AddressOverflow)?;
Ok(ImageSectionMetadata {
transfer_address: parsed
.image_base()
.checked_add(parsed.entry_point_rva())
.ok_or(PeImageAccessError::AddressOverflow)?,
file_size,
subsystem: u32::from(parsed.subsystem()),
subsystem_major_version: parsed.major_subsystem_version(),
subsystem_minor_version: parsed.minor_subsystem_version(),
image_characteristics: parsed.characteristics(),
dll_characteristics: parsed.dll_characteristics(),
machine: parsed.machine(),
})
}

fn load_image_with_writable_sections<Platform: crate::ShimPlatform, FS: ShimFS>(
fs: Arc<FS>,
path: &str,
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions litebox_common_windows/src/loader.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -489,6 +489,21 @@ impl PeParsedFile {
self.image.image_base
}

#[must_use]
pub fn machine(&self) -> u16 {
self.image.machine
}

#[must_use]
pub fn characteristics(&self) -> u16 {
self.image.characteristics
}

#[must_use]
pub fn dll_characteristics(&self) -> u16 {
self.image.dll_characteristics
}

/// Returns whether the image opts into dynamic-base loading.
#[must_use]
pub fn has_dynamic_base(&self) -> bool {
Expand Down
8 changes: 8 additions & 0 deletions litebox_common_windows/src/nt_status.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -159,6 +159,8 @@ impl NtStatus {
0xC0000046 => "STATUS_MUTANT_NOT_OWNED: Mutant not owned",
0xC0000047 => "STATUS_SEMAPHORE_LIMIT_EXCEEDED: Semaphore limit exceeded",
0xC0000048 => "STATUS_PORT_ALREADY_SET: Port already set",
0xC0000049 => "STATUS_SECTION_NOT_IMAGE: Section not image",
0xC000004E => "STATUS_SECTION_PROTECTION: Section protection",
0xC000004F => "STATUS_EAS_NOT_SUPPORTED: EAS not supported",
0xC0000050 => "STATUS_EA_TOO_LARGE: EA too large",
0xC0000056 => "STATUS_DELETE_PENDING: Delete pending",
Expand DownExpand Up@@ -420,6 +422,9 @@ impl NtStatus {
/// STATUS_SECTION_TOO_BIG
pub const SECTION_TOO_BIG: Self = Self::from_raw(0xC0000040);

/// STATUS_SECTION_NOT_IMAGE
pub const SECTION_NOT_IMAGE: Self = Self::from_raw(0xC0000049);

/// STATUS_PORT_CONNECTION_REFUSED
pub const PORT_CONNECTION_REFUSED: Self = Self::from_raw(0xC0000041);

Expand All@@ -435,6 +440,9 @@ impl NtStatus {
/// STATUS_INVALID_PAGE_PROTECTION
pub const INVALID_PAGE_PROTECTION: Self = Self::from_raw(0xC0000045);

/// STATUS_SECTION_PROTECTION
pub const SECTION_PROTECTION: Self = Self::from_raw(0xC000004E);

/// STATUS_MUTANT_NOT_OWNED
pub const MUTANT_NOT_OWNED: Self = Self::from_raw(0xC0000046);

Expand Down
184 changes: 184 additions & 0 deletions litebox_shim_windows/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,6 +38,9 @@ use crate::syscalls::event::{EventHandleObject, EventObject, EventSubsystem};
use crate::syscalls::file::{FileObject, FileObjectSubsystem};
use crate::syscalls::iocp::{IoCompletionHandleObject, IoCompletionSubsystem};
use crate::syscalls::registry::{RegistryKeyObject, RegistryKeySubsystem};
use crate::syscalls::section::{
MapViewOfSectionParameters, SectionHandleObject, SectionObject, SectionSubsystem,
};
use crate::syscalls::symlink::{SymbolicLinkHandleObject, SymbolicLinkSubsystem};
use crate::syscalls::timer::{TimerCreateParameters, TimerHandleObject, TimerSubsystem};
use crate::syscalls::wait_completion_packet::{
Expand DownExpand Up@@ -90,6 +93,10 @@ pub(crate) type WindowsNlsSectionMappings<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<(u32, u32), (usize, usize)>>;
pub(crate) type WindowsVirtualAllocations<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<usize, WindowsVirtualAllocation>>;
pub(crate) type WindowsSectionNamespace<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<String, Weak<SectionObject<Platform>>>>;
pub(crate) type WindowsSectionViews<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<usize, WindowsSectionView<Platform>>>;
pub(crate) type WindowsEventNamespace<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<String, Weak<EventObject<Platform>>>>;
pub(crate) type WindowsDirectoryNamespace<Platform> = DirectoryNamespace<Platform>;
Expand All@@ -103,6 +110,22 @@ pub(crate) struct WindowsVirtualAllocation {
pub(crate) pages: rangemap::RangeMap<usize, syscalls::mm::PageProtection>,
}

pub(crate) struct WindowsSectionView<Platform: ShimPlatform> {
pub(crate) size: usize,
pub(crate) section_offset: usize,
pub(crate) section: Option<Arc<SectionObject<Platform>>>,
}

impl<Platform: ShimPlatform> Clone for WindowsSectionView<Platform> {
fn clone(&self) -> Self {
Self {
size: self.size,
section_offset: self.section_offset,
section: self.section.clone(),
}
}
}

pub type DefaultFS<Platform> = WindowsFS<Platform>;

pub type WindowsFS<Platform> = litebox::fs::layered::FileSystem<
Expand DownExpand Up@@ -343,6 +366,8 @@ impl<Platform: ShimPlatform, FS: ShimFS> WindowsShim<Platform, FS> {
handles: WindowsHandleStore::<Platform>::new(litebox::fd::RawDescriptorStorage::new()),
directory_namespace,
event_namespace: WindowsEventNamespace::<Platform>::new(BTreeMap::new()),
section_namespace: WindowsSectionNamespace::<Platform>::new(BTreeMap::new()),
section_views: WindowsSectionViews::<Platform>::new(BTreeMap::new()),
nls_section_mappings: WindowsNlsSectionMappings::<Platform>::new(BTreeMap::new()),
virtual_allocations: load_info.virtual_allocations,
system_lcid: AtomicU32::new(syscalls::nls::DEFAULT_LOCALE_ID),
Expand DownExpand Up@@ -387,6 +412,8 @@ pub struct Process<Platform: ShimPlatform> {
handles: WindowsHandleStore<Platform>,
directory_namespace: WindowsDirectoryNamespace<Platform>,
event_namespace: WindowsEventNamespace<Platform>,
section_namespace: WindowsSectionNamespace<Platform>,
section_views: WindowsSectionViews<Platform>,
nls_section_mappings: WindowsNlsSectionMappings<Platform>,
virtual_allocations: WindowsVirtualAllocations<Platform>,
system_lcid: AtomicU32,
Expand DownExpand Up@@ -588,6 +615,15 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtOpenSection {
section_handle,
desired_access,
object_attributes,
} => {
let status =
self.sys_nt_open_section(section_handle, desired_access, object_attributes);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQueryDirectoryObject {
directory_handle,
buffer,
Expand DownExpand Up@@ -662,6 +698,50 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateSection {
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
} => {
let status = self.sys_nt_create_section(
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateSectionEx {
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
extended_parameters,
extended_parameter_count,
} => {
let status = self.sys_nt_create_section_ex(
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
extended_parameters,
extended_parameter_count,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateWaitCompletionPacket {
wait_completion_packet_handle,
desired_access,
Expand DownExpand Up@@ -1023,6 +1103,22 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQuerySection {
section_handle,
section_information_class,
section_information,
section_information_length,
return_length,
} => {
let status = self.sys_nt_query_section(
section_handle,
section_information_class,
section_information,
section_information_length,
return_length,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQueryInformationProcess {
process_handle,
process_information_class,
Expand DownExpand Up@@ -1199,6 +1295,80 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtMapViewOfSection {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
} => {
let status = self.sys_nt_map_view_of_section(MapViewOfSectionParameters {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
});
(status, ContinueOperation::Resume)
}
SyscallRequest::NtMapViewOfSectionEx {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
extended_parameters,
extended_parameter_count,
} => {
let status = self.sys_nt_map_view_of_section_ex(
MapViewOfSectionParameters {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
},
extended_parameters,
extended_parameter_count,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtUnmapViewOfSection {
process_handle,
base_address,
} => {
let status = self.sys_nt_unmap_view_of_section(process_handle, base_address);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtUnmapViewOfSectionEx {
process_handle,
base_address,
flags,
} => {
let status =
self.sys_nt_unmap_view_of_section_ex(process_handle, base_address, flags);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtTerminateProcess {
process_handle,
exit_status,
Expand DownExpand Up@@ -1306,6 +1476,14 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
) {
return NtStatus::SUCCESS;
}
if remove_raw_handle_by_raw_fd::<Platform, SectionSubsystem<Platform>>(
&self.global.litebox,
&self.process.handles,
raw_fd,
|section| visitor.section(section),
) {
return NtStatus::SUCCESS;
}
NtStatus::INVALID_HANDLE
}

Expand DownExpand Up@@ -1342,6 +1520,8 @@ trait RawHandleVisitor<Platform: ShimPlatform, FS: ShimFS> {
);

fn worker_factory(&self, worker_factory: WorkerFactoryHandleObject<Platform>);

fn section(&self, section: SectionHandleObject<Platform>);
}

struct CloseRawHandleVisitor<'task, Platform: ShimPlatform, FS: ShimFS> {
Expand DownExpand Up@@ -1389,6 +1569,10 @@ impl<Platform: ShimPlatform, FS: ShimFS> RawHandleVisitor<Platform, FS>
fn worker_factory(&self, worker_factory: WorkerFactoryHandleObject<Platform>) {
Task::<Platform, FS>::close_worker_factory(worker_factory);
}

fn section(&self, section: SectionHandleObject<Platform>) {
Task::<Platform, FS>::close_section(section);
}
}

/// The shim entrypoint object passed to the platform.
Expand Down
1 change: 1 addition & 0 deletions litebox_shim_windows/src/loader/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,3 +4,4 @@
mod pe;

pub(super) use pe::{PeLoader, WindowsLoadError};
pub(crate) use pe::{image_section_metadata, load_image_section};
52 changes: 52 additions & 0 deletions litebox_shim_windows/src/loader/pe.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1224,6 +1224,58 @@ fn load_image<Platform: crate::ShimPlatform, FS: ShimFS>(
load_image_with_writable_sections(fs, path, platform, page_manager, &[])
}

pub(crate) fn load_image_section<Platform: crate::ShimPlatform, FS: ShimFS>(
platform: &'static Platform,
fs: Arc<FS>,
path: &str,
page_manager: &crate::WindowsPageManager<Platform>,
virtual_allocations: &crate::WindowsVirtualAllocations<Platform>,
) -> Result<MappingInfo, WindowsLoadError> {
let image = load_image(platform, fs, path, page_manager)?;
let mapping = image.mapping;
register_image_virtual_allocation(virtual_allocations, mapping, image.pages);
Ok(mapping)
}

pub(crate) struct ImageSectionMetadata {
pub(crate) transfer_address: usize,
pub(crate) file_size: u32,
pub(crate) subsystem: u32,
pub(crate) subsystem_major_version: u16,
pub(crate) subsystem_minor_version: u16,
pub(crate) image_characteristics: u16,
pub(crate) dll_characteristics: u16,
pub(crate) machine: u16,
}

pub(crate) fn image_section_metadata<FS: ShimFS>(
fs: Arc<FS>,
path: &str,
) -> Result<ImageSectionMetadata, WindowsLoadError> {
let file = PeImageFile::open(fs, path)?;
let parsed = PeParsedFile::parse(&mut &file).map_err(WindowsLoadError::Parse)?;
let file_size = file
.fs
.fd_file_status(&file.fd)
.map_err(PeImageAccessError::FileStatus)?
.size
.try_into()
.map_err(|_| PeImageAccessError::AddressOverflow)?;
Ok(ImageSectionMetadata {
transfer_address: parsed
.image_base()
.checked_add(parsed.entry_point_rva())
.ok_or(PeImageAccessError::AddressOverflow)?,
file_size,
subsystem: u32::from(parsed.subsystem()),
subsystem_major_version: parsed.major_subsystem_version(),
subsystem_minor_version: parsed.minor_subsystem_version(),
image_characteristics: parsed.characteristics(),
dll_characteristics: parsed.dll_characteristics(),
machine: parsed.machine(),
})
}

fn load_image_with_writable_sections<Platform: crate::ShimPlatform, FS: ShimFS>(
fs: Arc<FS>,
path: &str,
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions litebox_common_windows/src/loader.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -489,6 +489,21 @@ impl PeParsedFile {
self.image.image_base
}

#[must_use]
pub fn machine(&self) -> u16 {
self.image.machine
}

#[must_use]
pub fn characteristics(&self) -> u16 {
self.image.characteristics
}

#[must_use]
pub fn dll_characteristics(&self) -> u16 {
self.image.dll_characteristics
}

/// Returns whether the image opts into dynamic-base loading.
#[must_use]
pub fn has_dynamic_base(&self) -> bool {
Expand Down
8 changes: 8 additions & 0 deletions litebox_common_windows/src/nt_status.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -159,6 +159,8 @@ impl NtStatus {
0xC0000046 => "STATUS_MUTANT_NOT_OWNED: Mutant not owned",
0xC0000047 => "STATUS_SEMAPHORE_LIMIT_EXCEEDED: Semaphore limit exceeded",
0xC0000048 => "STATUS_PORT_ALREADY_SET: Port already set",
0xC0000049 => "STATUS_SECTION_NOT_IMAGE: Section not image",
0xC000004E => "STATUS_SECTION_PROTECTION: Section protection",
0xC000004F => "STATUS_EAS_NOT_SUPPORTED: EAS not supported",
0xC0000050 => "STATUS_EA_TOO_LARGE: EA too large",
0xC0000056 => "STATUS_DELETE_PENDING: Delete pending",
Expand DownExpand Up@@ -420,6 +422,9 @@ impl NtStatus {
/// STATUS_SECTION_TOO_BIG
pub const SECTION_TOO_BIG: Self = Self::from_raw(0xC0000040);

/// STATUS_SECTION_NOT_IMAGE
pub const SECTION_NOT_IMAGE: Self = Self::from_raw(0xC0000049);

/// STATUS_PORT_CONNECTION_REFUSED
pub const PORT_CONNECTION_REFUSED: Self = Self::from_raw(0xC0000041);

Expand All@@ -435,6 +440,9 @@ impl NtStatus {
/// STATUS_INVALID_PAGE_PROTECTION
pub const INVALID_PAGE_PROTECTION: Self = Self::from_raw(0xC0000045);

/// STATUS_SECTION_PROTECTION
pub const SECTION_PROTECTION: Self = Self::from_raw(0xC000004E);

/// STATUS_MUTANT_NOT_OWNED
pub const MUTANT_NOT_OWNED: Self = Self::from_raw(0xC0000046);

Expand Down
184 changes: 184 additions & 0 deletions litebox_shim_windows/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,6 +38,9 @@ use crate::syscalls::event::{EventHandleObject, EventObject, EventSubsystem};
use crate::syscalls::file::{FileObject, FileObjectSubsystem};
use crate::syscalls::iocp::{IoCompletionHandleObject, IoCompletionSubsystem};
use crate::syscalls::registry::{RegistryKeyObject, RegistryKeySubsystem};
use crate::syscalls::section::{
MapViewOfSectionParameters, SectionHandleObject, SectionObject, SectionSubsystem,
};
use crate::syscalls::symlink::{SymbolicLinkHandleObject, SymbolicLinkSubsystem};
use crate::syscalls::timer::{TimerCreateParameters, TimerHandleObject, TimerSubsystem};
use crate::syscalls::wait_completion_packet::{
Expand DownExpand Up@@ -90,6 +93,10 @@ pub(crate) type WindowsNlsSectionMappings<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<(u32, u32), (usize, usize)>>;
pub(crate) type WindowsVirtualAllocations<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<usize, WindowsVirtualAllocation>>;
pub(crate) type WindowsSectionNamespace<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<String, Weak<SectionObject<Platform>>>>;
pub(crate) type WindowsSectionViews<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<usize, WindowsSectionView<Platform>>>;
pub(crate) type WindowsEventNamespace<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<String, Weak<EventObject<Platform>>>>;
pub(crate) type WindowsDirectoryNamespace<Platform> = DirectoryNamespace<Platform>;
Expand All@@ -103,6 +110,22 @@ pub(crate) struct WindowsVirtualAllocation {
pub(crate) pages: rangemap::RangeMap<usize, syscalls::mm::PageProtection>,
}

pub(crate) struct WindowsSectionView<Platform: ShimPlatform> {
pub(crate) size: usize,
pub(crate) section_offset: usize,
pub(crate) section: Option<Arc<SectionObject<Platform>>>,
}

impl<Platform: ShimPlatform> Clone for WindowsSectionView<Platform> {
fn clone(&self) -> Self {
Self {
size: self.size,
section_offset: self.section_offset,
section: self.section.clone(),
}
}
}

pub type DefaultFS<Platform> = WindowsFS<Platform>;

pub type WindowsFS<Platform> = litebox::fs::layered::FileSystem<
Expand DownExpand Up@@ -343,6 +366,8 @@ impl<Platform: ShimPlatform, FS: ShimFS> WindowsShim<Platform, FS> {
handles: WindowsHandleStore::<Platform>::new(litebox::fd::RawDescriptorStorage::new()),
directory_namespace,
event_namespace: WindowsEventNamespace::<Platform>::new(BTreeMap::new()),
section_namespace: WindowsSectionNamespace::<Platform>::new(BTreeMap::new()),
section_views: WindowsSectionViews::<Platform>::new(BTreeMap::new()),
nls_section_mappings: WindowsNlsSectionMappings::<Platform>::new(BTreeMap::new()),
virtual_allocations: load_info.virtual_allocations,
system_lcid: AtomicU32::new(syscalls::nls::DEFAULT_LOCALE_ID),
Expand DownExpand Up@@ -387,6 +412,8 @@ pub struct Process<Platform: ShimPlatform> {
handles: WindowsHandleStore<Platform>,
directory_namespace: WindowsDirectoryNamespace<Platform>,
event_namespace: WindowsEventNamespace<Platform>,
section_namespace: WindowsSectionNamespace<Platform>,
section_views: WindowsSectionViews<Platform>,
nls_section_mappings: WindowsNlsSectionMappings<Platform>,
virtual_allocations: WindowsVirtualAllocations<Platform>,
system_lcid: AtomicU32,
Expand DownExpand Up@@ -588,6 +615,15 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtOpenSection {
section_handle,
desired_access,
object_attributes,
} => {
let status =
self.sys_nt_open_section(section_handle, desired_access, object_attributes);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQueryDirectoryObject {
directory_handle,
buffer,
Expand DownExpand Up@@ -662,6 +698,50 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateSection {
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
} => {
let status = self.sys_nt_create_section(
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateSectionEx {
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
extended_parameters,
extended_parameter_count,
} => {
let status = self.sys_nt_create_section_ex(
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
extended_parameters,
extended_parameter_count,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateWaitCompletionPacket {
wait_completion_packet_handle,
desired_access,
Expand DownExpand Up@@ -1023,6 +1103,22 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQuerySection {
section_handle,
section_information_class,
section_information,
section_information_length,
return_length,
} => {
let status = self.sys_nt_query_section(
section_handle,
section_information_class,
section_information,
section_information_length,
return_length,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQueryInformationProcess {
process_handle,
process_information_class,
Expand DownExpand Up@@ -1199,6 +1295,80 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtMapViewOfSection {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
} => {
let status = self.sys_nt_map_view_of_section(MapViewOfSectionParameters {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
});
(status, ContinueOperation::Resume)
}
SyscallRequest::NtMapViewOfSectionEx {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
extended_parameters,
extended_parameter_count,
} => {
let status = self.sys_nt_map_view_of_section_ex(
MapViewOfSectionParameters {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
},
extended_parameters,
extended_parameter_count,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtUnmapViewOfSection {
process_handle,
base_address,
} => {
let status = self.sys_nt_unmap_view_of_section(process_handle, base_address);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtUnmapViewOfSectionEx {
process_handle,
base_address,
flags,
} => {
let status =
self.sys_nt_unmap_view_of_section_ex(process_handle, base_address, flags);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtTerminateProcess {
process_handle,
exit_status,
Expand DownExpand Up@@ -1306,6 +1476,14 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
) {
return NtStatus::SUCCESS;
}
if remove_raw_handle_by_raw_fd::<Platform, SectionSubsystem<Platform>>(
&self.global.litebox,
&self.process.handles,
raw_fd,
|section| visitor.section(section),
) {
return NtStatus::SUCCESS;
}
NtStatus::INVALID_HANDLE
}

Expand DownExpand Up@@ -1342,6 +1520,8 @@ trait RawHandleVisitor<Platform: ShimPlatform, FS: ShimFS> {
);

fn worker_factory(&self, worker_factory: WorkerFactoryHandleObject<Platform>);

fn section(&self, section: SectionHandleObject<Platform>);
}

struct CloseRawHandleVisitor<'task, Platform: ShimPlatform, FS: ShimFS> {
Expand DownExpand Up@@ -1389,6 +1569,10 @@ impl<Platform: ShimPlatform, FS: ShimFS> RawHandleVisitor<Platform, FS>
fn worker_factory(&self, worker_factory: WorkerFactoryHandleObject<Platform>) {
Task::<Platform, FS>::close_worker_factory(worker_factory);
}

fn section(&self, section: SectionHandleObject<Platform>) {
Task::<Platform, FS>::close_section(section);
}
}

/// The shim entrypoint object passed to the platform.
Expand Down
1 change: 1 addition & 0 deletions litebox_shim_windows/src/loader/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,3 +4,4 @@
mod pe;

pub(super) use pe::{PeLoader, WindowsLoadError};
pub(crate) use pe::{image_section_metadata, load_image_section};
52 changes: 52 additions & 0 deletions litebox_shim_windows/src/loader/pe.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1224,6 +1224,58 @@ fn load_image<Platform: crate::ShimPlatform, FS: ShimFS>(
load_image_with_writable_sections(fs, path, platform, page_manager, &[])
}

pub(crate) fn load_image_section<Platform: crate::ShimPlatform, FS: ShimFS>(
platform: &'static Platform,
fs: Arc<FS>,
path: &str,
page_manager: &crate::WindowsPageManager<Platform>,
virtual_allocations: &crate::WindowsVirtualAllocations<Platform>,
) -> Result<MappingInfo, WindowsLoadError> {
let image = load_image(platform, fs, path, page_manager)?;
let mapping = image.mapping;
register_image_virtual_allocation(virtual_allocations, mapping, image.pages);
Ok(mapping)
}

pub(crate) struct ImageSectionMetadata {
pub(crate) transfer_address: usize,
pub(crate) file_size: u32,
pub(crate) subsystem: u32,
pub(crate) subsystem_major_version: u16,
pub(crate) subsystem_minor_version: u16,
pub(crate) image_characteristics: u16,
pub(crate) dll_characteristics: u16,
pub(crate) machine: u16,
}

pub(crate) fn image_section_metadata<FS: ShimFS>(
fs: Arc<FS>,
path: &str,
) -> Result<ImageSectionMetadata, WindowsLoadError> {
let file = PeImageFile::open(fs, path)?;
let parsed = PeParsedFile::parse(&mut &file).map_err(WindowsLoadError::Parse)?;
let file_size = file
.fs
.fd_file_status(&file.fd)
.map_err(PeImageAccessError::FileStatus)?
.size
.try_into()
.map_err(|_| PeImageAccessError::AddressOverflow)?;
Ok(ImageSectionMetadata {
transfer_address: parsed
.image_base()
.checked_add(parsed.entry_point_rva())
.ok_or(PeImageAccessError::AddressOverflow)?,
file_size,
subsystem: u32::from(parsed.subsystem()),
subsystem_major_version: parsed.major_subsystem_version(),
subsystem_minor_version: parsed.minor_subsystem_version(),
image_characteristics: parsed.characteristics(),
dll_characteristics: parsed.dll_characteristics(),
machine: parsed.machine(),
})
}

fn load_image_with_writable_sections<Platform: crate::ShimPlatform, FS: ShimFS>(
fs: Arc<FS>,
path: &str,
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions litebox_common_windows/src/loader.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -489,6 +489,21 @@ impl PeParsedFile {
self.image.image_base
}

#[must_use]
pub fn machine(&self) -> u16 {
self.image.machine
}

#[must_use]
pub fn characteristics(&self) -> u16 {
self.image.characteristics
}

#[must_use]
pub fn dll_characteristics(&self) -> u16 {
self.image.dll_characteristics
}

/// Returns whether the image opts into dynamic-base loading.
#[must_use]
pub fn has_dynamic_base(&self) -> bool {
Expand Down
8 changes: 8 additions & 0 deletions litebox_common_windows/src/nt_status.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -159,6 +159,8 @@ impl NtStatus {
0xC0000046 => "STATUS_MUTANT_NOT_OWNED: Mutant not owned",
0xC0000047 => "STATUS_SEMAPHORE_LIMIT_EXCEEDED: Semaphore limit exceeded",
0xC0000048 => "STATUS_PORT_ALREADY_SET: Port already set",
0xC0000049 => "STATUS_SECTION_NOT_IMAGE: Section not image",
0xC000004E => "STATUS_SECTION_PROTECTION: Section protection",
0xC000004F => "STATUS_EAS_NOT_SUPPORTED: EAS not supported",
0xC0000050 => "STATUS_EA_TOO_LARGE: EA too large",
0xC0000056 => "STATUS_DELETE_PENDING: Delete pending",
Expand DownExpand Up@@ -420,6 +422,9 @@ impl NtStatus {
/// STATUS_SECTION_TOO_BIG
pub const SECTION_TOO_BIG: Self = Self::from_raw(0xC0000040);

/// STATUS_SECTION_NOT_IMAGE
pub const SECTION_NOT_IMAGE: Self = Self::from_raw(0xC0000049);

/// STATUS_PORT_CONNECTION_REFUSED
pub const PORT_CONNECTION_REFUSED: Self = Self::from_raw(0xC0000041);

Expand All@@ -435,6 +440,9 @@ impl NtStatus {
/// STATUS_INVALID_PAGE_PROTECTION
pub const INVALID_PAGE_PROTECTION: Self = Self::from_raw(0xC0000045);

/// STATUS_SECTION_PROTECTION
pub const SECTION_PROTECTION: Self = Self::from_raw(0xC000004E);

/// STATUS_MUTANT_NOT_OWNED
pub const MUTANT_NOT_OWNED: Self = Self::from_raw(0xC0000046);

Expand Down
184 changes: 184 additions & 0 deletions litebox_shim_windows/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -38,6 +38,9 @@ use crate::syscalls::event::{EventHandleObject, EventObject, EventSubsystem};
use crate::syscalls::file::{FileObject, FileObjectSubsystem};
use crate::syscalls::iocp::{IoCompletionHandleObject, IoCompletionSubsystem};
use crate::syscalls::registry::{RegistryKeyObject, RegistryKeySubsystem};
use crate::syscalls::section::{
MapViewOfSectionParameters, SectionHandleObject, SectionObject, SectionSubsystem,
};
use crate::syscalls::symlink::{SymbolicLinkHandleObject, SymbolicLinkSubsystem};
use crate::syscalls::timer::{TimerCreateParameters, TimerHandleObject, TimerSubsystem};
use crate::syscalls::wait_completion_packet::{
Expand DownExpand Up@@ -90,6 +93,10 @@ pub(crate) type WindowsNlsSectionMappings<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<(u32, u32), (usize, usize)>>;
pub(crate) type WindowsVirtualAllocations<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<usize, WindowsVirtualAllocation>>;
pub(crate) type WindowsSectionNamespace<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<String, Weak<SectionObject<Platform>>>>;
pub(crate) type WindowsSectionViews<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<usize, WindowsSectionView<Platform>>>;
pub(crate) type WindowsEventNamespace<Platform> =
litebox::sync::RwLock<Platform, BTreeMap<String, Weak<EventObject<Platform>>>>;
pub(crate) type WindowsDirectoryNamespace<Platform> = DirectoryNamespace<Platform>;
Expand All@@ -103,6 +110,22 @@ pub(crate) struct WindowsVirtualAllocation {
pub(crate) pages: rangemap::RangeMap<usize, syscalls::mm::PageProtection>,
}

pub(crate) struct WindowsSectionView<Platform: ShimPlatform> {
pub(crate) size: usize,
pub(crate) section_offset: usize,
pub(crate) section: Option<Arc<SectionObject<Platform>>>,
}

impl<Platform: ShimPlatform> Clone for WindowsSectionView<Platform> {
fn clone(&self) -> Self {
Self {
size: self.size,
section_offset: self.section_offset,
section: self.section.clone(),
}
}
}

pub type DefaultFS<Platform> = WindowsFS<Platform>;

pub type WindowsFS<Platform> = litebox::fs::layered::FileSystem<
Expand DownExpand Up@@ -343,6 +366,8 @@ impl<Platform: ShimPlatform, FS: ShimFS> WindowsShim<Platform, FS> {
handles: WindowsHandleStore::<Platform>::new(litebox::fd::RawDescriptorStorage::new()),
directory_namespace,
event_namespace: WindowsEventNamespace::<Platform>::new(BTreeMap::new()),
section_namespace: WindowsSectionNamespace::<Platform>::new(BTreeMap::new()),
section_views: WindowsSectionViews::<Platform>::new(BTreeMap::new()),
nls_section_mappings: WindowsNlsSectionMappings::<Platform>::new(BTreeMap::new()),
virtual_allocations: load_info.virtual_allocations,
system_lcid: AtomicU32::new(syscalls::nls::DEFAULT_LOCALE_ID),
Expand DownExpand Up@@ -387,6 +412,8 @@ pub struct Process<Platform: ShimPlatform> {
handles: WindowsHandleStore<Platform>,
directory_namespace: WindowsDirectoryNamespace<Platform>,
event_namespace: WindowsEventNamespace<Platform>,
section_namespace: WindowsSectionNamespace<Platform>,
section_views: WindowsSectionViews<Platform>,
nls_section_mappings: WindowsNlsSectionMappings<Platform>,
virtual_allocations: WindowsVirtualAllocations<Platform>,
system_lcid: AtomicU32,
Expand DownExpand Up@@ -588,6 +615,15 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtOpenSection {
section_handle,
desired_access,
object_attributes,
} => {
let status =
self.sys_nt_open_section(section_handle, desired_access, object_attributes);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQueryDirectoryObject {
directory_handle,
buffer,
Expand DownExpand Up@@ -662,6 +698,50 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateSection {
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
} => {
let status = self.sys_nt_create_section(
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateSectionEx {
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
extended_parameters,
extended_parameter_count,
} => {
let status = self.sys_nt_create_section_ex(
section_handle,
desired_access,
object_attributes,
maximum_size,
section_page_protection,
allocation_attributes,
file_handle,
extended_parameters,
extended_parameter_count,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtCreateWaitCompletionPacket {
wait_completion_packet_handle,
desired_access,
Expand DownExpand Up@@ -1023,6 +1103,22 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQuerySection {
section_handle,
section_information_class,
section_information,
section_information_length,
return_length,
} => {
let status = self.sys_nt_query_section(
section_handle,
section_information_class,
section_information,
section_information_length,
return_length,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtQueryInformationProcess {
process_handle,
process_information_class,
Expand DownExpand Up@@ -1199,6 +1295,80 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtMapViewOfSection {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
} => {
let status = self.sys_nt_map_view_of_section(MapViewOfSectionParameters {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
});
(status, ContinueOperation::Resume)
}
SyscallRequest::NtMapViewOfSectionEx {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
extended_parameters,
extended_parameter_count,
} => {
let status = self.sys_nt_map_view_of_section_ex(
MapViewOfSectionParameters {
section_handle,
process_handle,
base_address,
zero_bits,
commit_size,
section_offset,
view_size,
inherit_disposition,
allocation_type,
page_protection,
},
extended_parameters,
extended_parameter_count,
);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtUnmapViewOfSection {
process_handle,
base_address,
} => {
let status = self.sys_nt_unmap_view_of_section(process_handle, base_address);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtUnmapViewOfSectionEx {
process_handle,
base_address,
flags,
} => {
let status =
self.sys_nt_unmap_view_of_section_ex(process_handle, base_address, flags);
(status, ContinueOperation::Resume)
}
SyscallRequest::NtTerminateProcess {
process_handle,
exit_status,
Expand DownExpand Up@@ -1306,6 +1476,14 @@ impl<Platform: ShimPlatform, FS: ShimFS> Task<Platform, FS> {
) {
return NtStatus::SUCCESS;
}
if remove_raw_handle_by_raw_fd::<Platform, SectionSubsystem<Platform>>(
&self.global.litebox,
&self.process.handles,
raw_fd,
|section| visitor.section(section),
) {
return NtStatus::SUCCESS;
}
NtStatus::INVALID_HANDLE
}

Expand DownExpand Up@@ -1342,6 +1520,8 @@ trait RawHandleVisitor<Platform: ShimPlatform, FS: ShimFS> {
);

fn worker_factory(&self, worker_factory: WorkerFactoryHandleObject<Platform>);

fn section(&self, section: SectionHandleObject<Platform>);
}

struct CloseRawHandleVisitor<'task, Platform: ShimPlatform, FS: ShimFS> {
Expand DownExpand Up@@ -1389,6 +1569,10 @@ impl<Platform: ShimPlatform, FS: ShimFS> RawHandleVisitor<Platform, FS>
fn worker_factory(&self, worker_factory: WorkerFactoryHandleObject<Platform>) {
Task::<Platform, FS>::close_worker_factory(worker_factory);
}

fn section(&self, section: SectionHandleObject<Platform>) {
Task::<Platform, FS>::close_section(section);
}
}

/// The shim entrypoint object passed to the platform.
Expand Down
1 change: 1 addition & 0 deletions litebox_shim_windows/src/loader/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,3 +4,4 @@
mod pe;

pub(super) use pe::{PeLoader, WindowsLoadError};
pub(crate) use pe::{image_section_metadata, load_image_section};
52 changes: 52 additions & 0 deletions litebox_shim_windows/src/loader/pe.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1224,6 +1224,58 @@ fn load_image<Platform: crate::ShimPlatform, FS: ShimFS>(
load_image_with_writable_sections(fs, path, platform, page_manager, &[])
}

pub(crate) fn load_image_section<Platform: crate::ShimPlatform, FS: ShimFS>(
platform: &'static Platform,
fs: Arc<FS>,
path: &str,
page_manager: &crate::WindowsPageManager<Platform>,
virtual_allocations: &crate::WindowsVirtualAllocations<Platform>,
) -> Result<MappingInfo, WindowsLoadError> {
let image = load_image(platform, fs, path, page_manager)?;
let mapping = image.mapping;
register_image_virtual_allocation(virtual_allocations, mapping, image.pages);
Ok(mapping)
}

pub(crate) struct ImageSectionMetadata {
pub(crate) transfer_address: usize,
pub(crate) file_size: u32,
pub(crate) subsystem: u32,
pub(crate) subsystem_major_version: u16,
pub(crate) subsystem_minor_version: u16,
pub(crate) image_characteristics: u16,
pub(crate) dll_characteristics: u16,
pub(crate) machine: u16,
}

pub(crate) fn image_section_metadata<FS: ShimFS>(
fs: Arc<FS>,
path: &str,
) -> Result<ImageSectionMetadata, WindowsLoadError> {
let file = PeImageFile::open(fs, path)?;
let parsed = PeParsedFile::parse(&mut &file).map_err(WindowsLoadError::Parse)?;
let file_size = file
.fs
.fd_file_status(&file.fd)
.map_err(PeImageAccessError::FileStatus)?
.size
.try_into()
.map_err(|_| PeImageAccessError::AddressOverflow)?;
Ok(ImageSectionMetadata {
transfer_address: parsed
.image_base()
.checked_add(parsed.entry_point_rva())
.ok_or(PeImageAccessError::AddressOverflow)?,
file_size,
subsystem: u32::from(parsed.subsystem()),
subsystem_major_version: parsed.major_subsystem_version(),
subsystem_minor_version: parsed.minor_subsystem_version(),
image_characteristics: parsed.characteristics(),
dll_characteristics: parsed.dll_characteristics(),
machine: parsed.machine(),
})
}

fn load_image_with_writable_sections<Platform: crate::ShimPlatform, FS: ShimFS>(
fs: Arc<FS>,
path: &str,
Expand Down
Loading