ethanblake4 / dart_eval

Extensible Dart interpreter for Dart with full interop
https://pub.dev/packages/dart_eval
BSD 3-Clause "New" or "Revised" License
334 stars 40 forks source link

type 'Keyword' is not a subtype of type 'String' in type cast #129

Closed Noobware1 closed 1 year ago

Noobware1 commented 1 year ago

this error is occuring when i try access a decoded json value and cast it to a list type in this line
var source = decrypted['source'] as List

if i remove this line from the code it works fine but the error even occurs when using .map without casting using list generate without casting and i if try do a for in loop and a simple for loop without casting it throws this error

dart_eval runtime exception: type 'bool' is not a subtype of type '$Instance' in type cast
#0      InvokeDynamic.run (package:dart_eval/src/eval/runtime/ops/objects.dart:92:31)
#1      Runtime.bridgeCall (package:dart_eval/src/eval/runtime/runtime.dart:693:12)
#2      EvalStaticFunctionPtr.call (package:dart_eval/src/eval/runtime/function.dart:78:13)

this is what the decoded json looks like

{$"source": Instance of '$List<$Value?>', $"source_bk": Instance of '$List<$Value?>', $"track": Instance of '$Map<$Value?, $Value?>', $"advertising": Instance of '$List<$Value?>', $"linkiframe": $"https://awish.pro/e/dlvko8lituey"}

here's the full error

type 'Keyword' is not a subtype of type 'String' in type cast
#0      PrescanVisitor.visitVariableDeclaration (package:dart_eval/src/eval/compiler/optimizer/prescan.dart:30:36)
#1      VariableDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:18806:50)
#2      NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:13037:20)
#3      VariableDeclarationListImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:18949:16)
#4      RecursiveAstVisitor.visitVariableDeclarationList (package:analyzer/dart/ast/visitor.dart:1780:10)
#5      VariableDeclarationListImpl.accept (package:analyzer/src/dart/ast/ast.dart:18943:15)
#6      VariableDeclarationStatementImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:19012:19)
#7      RecursiveAstVisitor.visitVariableDeclarationStatement (package:analyzer/dart/ast/visitor.dart:1786:10)
#8      VariableDeclarationStatementImpl.accept (package:analyzer/src/dart/ast/ast.dart:19008:15)
#9      NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:13037:20)
#10     BlockImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:1980:17)
#11     PrescanVisitor.visitBlock (package:dart_eval/src/eval/compiler/optimizer/prescan.dart:36:10)
#12     BlockImpl.accept (package:analyzer/src/dart/ast/ast.dart:1976:50)
#13     BlockFunctionBodyImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:1931:12)
#14     RecursiveAstVisitor.visitBlockFunctionBody (package:analyzer/dart/ast/visitor.dart:870:10)
#15     BlockFunctionBodyImpl.accept (package:analyzer/src/dart/ast/ast.dart:1923:50)
#16     MethodDeclarationImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:12164:10)
#17     CompilerContext.runPrescan (package:dart_eval/src/eval/compiler/context.dart:258:7)
#18     compileMethodDeclaration (package:dart_eval/src/eval/compiler/declaration/method.dart:17:7)
#19     compileDeclaration (package:dart_eval/src/eval/compiler/declaration/declaration.dart:21:12)
#20     compileClassDeclaration (package:dart_eval/src/eval/compiler/declaration/class.dart:35:5)
#21     compileDeclaration (package:dart_eval/src/eval/compiler/declaration/declaration.dart:17:5)
#22     Compiler.compileSources.<anonymous closure>.<anonymous closure> (package:dart_eval/src/eval/compiler/compiler.dart:427:11)
#23     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:625:13)
#24     Compiler.compileSources.<anonymous closure> (package:dart_eval/src/eval/compiler/compiler.dart:416:15)
#25     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:625:13)
#26     Compiler.compileSources (package:dart_eval/src/eval/compiler/compiler.dart:413:32)
#27     Compiler.compile (package:dart_eval/src/eval/compiler/compiler.dart:146:12)
#28     compilerEval (package:extenstions_test/extenstions_test.dart:76:28)
<asynchronous suspension>
#29     main (package:extenstions_test/extenstions_test.dart:159:20)
<asynchronous suspension>

and here's the full code

import 'dart:convert';
import 'package:bridge_lib/bridge_lib.dart';

getExtractor() {
  return GogoCDN(ExtractorLink(
      url:
          'https://goone.pro/streaming.php?id=MjEzOTY3&amp;title=Tokyo+Revengers%3A+Tenjiku-hen+Episode+4'));
}

class GogoCDN extends ExtractorApi {
  GogoCDN(ExtractorLink extractorLink) : super(extractorLink);

  @override
  Future<Media> extract() async {
    final doc = (await MeiyouUtils.httpRequest(
            url: this.extractorLink.url, method: 'GET'))
        .document;

    final script =
        doc.selectFirst('script[data-name="episode"]').attr('data-value');
    final id = doc.selectFirst('#id').attr('value');
    print(id);

    final host = MeiyouUtils.getHost(this.extractorLink.url);

    final encryptedID = cryptoHandler(keysAndIV.key, keysAndIV.iv, id, true);

    print(encryptedID);

    final decryptedID =
        cryptoHandler(keysAndIV.key, keysAndIV.iv, script, false)
            .replaceFirst(id, encryptedID);

    final encryptedData = json.decode((await MeiyouUtils.httpRequest(
            url: 'https://$host/encrypt-ajax.php?id=$decryptedID&alias=$id',
            method: 'GET',
            headers: {'x-requested-with': 'XMLHttpRequest'}))
        .text)['data'] as String;
    print(encryptedData);

    final decrypted = json.decode(
        cryptoHandler(keysAndIV.secondKey, keysAndIV.iv, encryptedData, false));

    final List<VideoSource> list = [];

    var source = decrypted['source'] as List;

    return Video(videoSources: list, headers: {'referer': 'https://$host'});
  }

  VideoSource toVideoSource(dynamic json, bool backup) {
    final label = json['label'];
    final url = json['file'];
    if (label != "auto P" && label != "hls P") {
      return VideoSource(
        url: url,
        quality: VideoQuality.getFromString(label),
        format: VideoFormat.other,
        isBackup: backup,
      );
    } else {
      return VideoSource(
        url: url,
        format: VideoFormat.hls,
        isBackup: backup,
      );
    }
  }

  static const keysAndIV = Keys('37911490979715163134003223491201',
      '54674138327930866480207815084989', '3134003223491201');

  String cryptoHandler(String key, String iv, String text, bool encrypt) {
    if (encrypt) {
      return CryptoUtils.cryptoJsAes(
        ciphertext: text,
        key: key,
        iv: iv,
        encrypt: encrypt,
        ivEncoding: 'utf8',
        keyEncoding: 'utf8',
        textEncoding: 'utf8',
        encoding: 'base64',
      );
    } else {
      return CryptoUtils.cryptoJsAes(
          ciphertext: text,
          key: key,
          iv: iv,
          encrypt: encrypt,
          ivEncoding: 'utf8',
          keyEncoding: 'utf8',
          textEncoding: 'base64');
    }
  }
}

class Keys {
  final String key;
  final String secondKey;
  final String iv;

  const Keys(this.key, this.secondKey, this.iv);
}
Noobware1 commented 1 year ago

@ethanblake4 you can closed this issue if want found out that && operator in a if statement was the cause. is it not supported?

Edit also found out you can't add a mapped list using addAll as it throws this error

type 'MappedListIterable<$Value?, dynamic>' is not a subtype of type 'Iterable<$Value>' of 'iterable'
ethanblake4 commented 1 year ago

Will be fixed in v0.7. In the meantime you can avoid this by not using the word "label" which is a keyword in dart

ethanblake4 commented 1 year ago

Fixed in v0.7.0