diff --git a/crates/untwist-deobfuscate/src/calls/agnostic/foreign.rs b/crates/untwist-deobfuscate/src/calls/agnostic/foreign.rs
new file mode 100644
index 00000000..72ae1f3e
--- /dev/null
+++ b/crates/untwist-deobfuscate/src/calls/agnostic/foreign.rs
@@ -0,0 +1,542 @@
+use oxc_ast::ast::*;
+use oxc_ast_visit::{walk_js, VisitJs};
+use oxc_semantic::Scoping;
+use oxc_syntax::symbol::SymbolId;
+
+use super::defs::Defs;
+use super::sites::Sites;
+
+const LOCAL_DEPTH: u8 = 8;
+
+const GLOBAL_OBJECTS: [&str; 7] = [
+ "globalThis",
+ "window",
+ "self",
+ "top",
+ "parent",
+ "frames",
+ "global",
+];
+
+pub(super) fn sourced(program: &Program<'_>, scoping: &Scoping) -> bool {
+ if !untwist_core::semantic::other_inputs_given() {
+ return false;
+ }
+ if untwist_core::semantic::every_global_foreign() {
+ return true;
+ }
+ let mut scan = Sources {
+ scoping,
+ found: false,
+ };
+ scan.visit_program(program);
+ scan.found
+}
+
+struct Sources<'s> {
+ scoping: &'s Scoping,
+ found: bool,
+}
+
+impl Sources<'_> {
+ fn global_object(&self, expr: &Expression<'_>) -> bool {
+ matches!(expr.without_parentheses(), Expression::Identifier(id)
+ if GLOBAL_OBJECTS.contains(&id.name.as_str()) && self.unresolved(id))
+ }
+
+ fn unresolved(&self, id: &IdentifierReference<'_>) -> bool {
+ id.reference_id
+ .get()
+ .and_then(|reference| self.scoping.get_reference(reference).symbol_id())
+ .is_none()
+ }
+}
+
+fn foreign_name(name: &str) -> bool {
+ untwist_core::semantic::is_foreign_global(name)
+}
+
+impl<'a> VisitJs<'a> for Sources<'_> {
+ fn visit_identifier_reference(&mut self, it: &IdentifierReference<'a>) {
+ if !foreign_name(it.name.as_str()) {
+ return;
+ }
+ let symbol = it
+ .reference_id
+ .get()
+ .and_then(|reference| self.scoping.get_reference(reference).symbol_id());
+ self.found |= symbol.is_none_or(|symbol| {
+ self.scoping.symbol_scope_id(symbol) == self.scoping.root_scope_id()
+ });
+ }
+
+ fn visit_static_member_expression(&mut self, it: &StaticMemberExpression<'a>) {
+ self.found |= foreign_name(it.property.name.as_str());
+ walk_js::walk_static_member_expression(self, it);
+ }
+
+ fn visit_computed_member_expression(&mut self, it: &ComputedMemberExpression<'a>) {
+ let literal = matches!(
+ it.expression.without_parentheses(),
+ Expression::StringLiteral(_) | Expression::NumericLiteral(_)
+ );
+ self.found |= !literal && self.global_object(&it.object);
+ walk_js::walk_computed_member_expression(self, it);
+ }
+
+ fn visit_string_literal(&mut self, it: &StringLiteral<'a>) {
+ self.found |= it.value.as_str().is_some_and(foreign_name);
+ }
+
+ fn visit_template_element(&mut self, it: &TemplateElement<'a>) {
+ self.found |= it
+ .value
+ .cooked
+ .and_then(|cooked| cooked.as_str())
+ .is_some_and(foreign_name);
+ }
+
+ fn visit_binding_identifier(&mut self, it: &BindingIdentifier<'a>) {
+ self.found |= foreign_name(it.name.as_str())
+ && it.symbol_id.get().is_some_and(|symbol| {
+ self.scoping.symbol_scope_id(symbol) == self.scoping.root_scope_id()
+ });
+ }
+}
+
+fn returns_of<'k, 'a>(statements: &'k [Statement<'a>], out: &mut Vec