Mercurial > paraspace
comparison paraspace/injection.py @ 154:c659b8c7d6cb
Use right opcode formats
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 17 Aug 2011 08:36:33 +0800 |
parents | bc213cb88636 |
children |
comparison
equal
deleted
inserted
replaced
153:9a1677d03417 | 154:c659b8c7d6cb |
---|---|
346 stridx = args[1] | 346 stridx = args[1] |
347 return stridx | 347 return stridx |
348 | 348 |
349 return None | 349 return None |
350 | 350 |
351 field_opcodes = set([all_opcodes.OP_IGET, | 351 field2_opcodes = set([all_opcodes.OP_IGET, |
352 all_opcodes.OP_IGET_WIDE, | 352 all_opcodes.OP_IGET_WIDE, |
353 all_opcodes.OP_IGET_OBJECT, | 353 all_opcodes.OP_IGET_OBJECT, |
354 all_opcodes.OP_IGET_BOOLEAN, | 354 all_opcodes.OP_IGET_BOOLEAN, |
355 all_opcodes.OP_IGET_BYTE, | 355 all_opcodes.OP_IGET_BYTE, |
356 all_opcodes.OP_IGET_CHAR, | 356 all_opcodes.OP_IGET_CHAR, |
359 all_opcodes.OP_IPUT_WIDE, | 359 all_opcodes.OP_IPUT_WIDE, |
360 all_opcodes.OP_IPUT_OBJECT, | 360 all_opcodes.OP_IPUT_OBJECT, |
361 all_opcodes.OP_IPUT_BOOLEAN, | 361 all_opcodes.OP_IPUT_BOOLEAN, |
362 all_opcodes.OP_IPUT_BYTE, | 362 all_opcodes.OP_IPUT_BYTE, |
363 all_opcodes.OP_IPUT_CHAR, | 363 all_opcodes.OP_IPUT_CHAR, |
364 all_opcodes.OP_IPUT_SHORT, | 364 all_opcodes.OP_IPUT_SHORT]) |
365 all_opcodes.OP_SGET, | 365 |
366 all_opcodes.OP_SGET_WIDE, | 366 field1_opcodes = set([all_opcodes.OP_SGET, |
367 all_opcodes.OP_SGET_OBJECT, | 367 all_opcodes.OP_SGET_WIDE, |
368 all_opcodes.OP_SGET_BOOLEAN, | 368 all_opcodes.OP_SGET_OBJECT, |
369 all_opcodes.OP_SGET_BYTE, | 369 all_opcodes.OP_SGET_BOOLEAN, |
370 all_opcodes.OP_SGET_CHAR, | 370 all_opcodes.OP_SGET_BYTE, |
371 all_opcodes.OP_SGET_SHORT, | 371 all_opcodes.OP_SGET_CHAR, |
372 all_opcodes.OP_SPUT, | 372 all_opcodes.OP_SGET_SHORT, |
373 all_opcodes.OP_SPUT_WIDE, | 373 all_opcodes.OP_SPUT, |
374 all_opcodes.OP_SPUT_OBJECT, | 374 all_opcodes.OP_SPUT_WIDE, |
375 all_opcodes.OP_SPUT_BOOLEAN, | 375 all_opcodes.OP_SPUT_OBJECT, |
376 all_opcodes.OP_SPUT_BYTE, | 376 all_opcodes.OP_SPUT_BOOLEAN, |
377 all_opcodes.OP_SPUT_CHAR, | 377 all_opcodes.OP_SPUT_BYTE, |
378 all_opcodes.OP_SPUT_SHORT]) | 378 all_opcodes.OP_SPUT_CHAR, |
379 all_opcodes.OP_SPUT_SHORT]) | |
380 | |
379 def collect_fields_in_op_vector(op_vector): | 381 def collect_fields_in_op_vector(op_vector): |
380 code, args = op_vector | 382 code, args = op_vector |
381 if code in field_opcodes: | 383 if code in field2_opcodes: |
382 fieldidx = args[2] | 384 fieldidx = args[2] |
385 return fieldidx | |
386 elif code in field1_opcodes: | |
387 fieldidx = args[1] | |
383 return fieldidx | 388 return fieldidx |
384 pass | 389 pass |
385 | 390 |
386 code_blk = DEXFile_linked.get_code_block_method(method) | 391 code_blk = DEXFile_linked.get_code_block_method(method) |
387 op_vectors = decode_insn_blk(code_blk) | 392 op_vectors = decode_insn_blk(code_blk) |
603 | 608 |
604 code = method.codeOffRef.value | 609 code = method.codeOffRef.value |
605 insns_blk = code.insns.data | 610 insns_blk = code.insns.data |
606 op_vectors = decode_insn_blk(insns_blk) | 611 op_vectors = decode_insn_blk(insns_blk) |
607 | 612 |
608 field_opcodes = set([all_opcodes.OP_IGET, | 613 field2_opcodes = set([all_opcodes.OP_IGET, |
609 all_opcodes.OP_IGET_WIDE, | 614 all_opcodes.OP_IGET_WIDE, |
610 all_opcodes.OP_IGET_OBJECT, | 615 all_opcodes.OP_IGET_OBJECT, |
611 all_opcodes.OP_IGET_BOOLEAN, | 616 all_opcodes.OP_IGET_BOOLEAN, |
612 all_opcodes.OP_IGET_BYTE, | 617 all_opcodes.OP_IGET_BYTE, |
613 all_opcodes.OP_IGET_CHAR, | 618 all_opcodes.OP_IGET_CHAR, |
616 all_opcodes.OP_IPUT_WIDE, | 621 all_opcodes.OP_IPUT_WIDE, |
617 all_opcodes.OP_IPUT_OBJECT, | 622 all_opcodes.OP_IPUT_OBJECT, |
618 all_opcodes.OP_IPUT_BOOLEAN, | 623 all_opcodes.OP_IPUT_BOOLEAN, |
619 all_opcodes.OP_IPUT_BYTE, | 624 all_opcodes.OP_IPUT_BYTE, |
620 all_opcodes.OP_IPUT_CHAR, | 625 all_opcodes.OP_IPUT_CHAR, |
621 all_opcodes.OP_IPUT_SHORT, | 626 all_opcodes.OP_IPUT_SHORT]) |
622 all_opcodes.OP_SGET, | 627 |
623 all_opcodes.OP_SGET_WIDE, | 628 field1_opcodes = set([all_opcodes.OP_SGET, |
624 all_opcodes.OP_SGET_OBJECT, | 629 all_opcodes.OP_SGET_WIDE, |
625 all_opcodes.OP_SGET_BOOLEAN, | 630 all_opcodes.OP_SGET_OBJECT, |
626 all_opcodes.OP_SGET_BYTE, | 631 all_opcodes.OP_SGET_BOOLEAN, |
627 all_opcodes.OP_SGET_CHAR, | 632 all_opcodes.OP_SGET_BYTE, |
628 all_opcodes.OP_SGET_SHORT, | 633 all_opcodes.OP_SGET_CHAR, |
629 all_opcodes.OP_SPUT, | 634 all_opcodes.OP_SGET_SHORT, |
630 all_opcodes.OP_SPUT_WIDE, | 635 all_opcodes.OP_SPUT, |
631 all_opcodes.OP_SPUT_OBJECT, | 636 all_opcodes.OP_SPUT_WIDE, |
632 all_opcodes.OP_SPUT_BOOLEAN, | 637 all_opcodes.OP_SPUT_OBJECT, |
633 all_opcodes.OP_SPUT_BYTE, | 638 all_opcodes.OP_SPUT_BOOLEAN, |
634 all_opcodes.OP_SPUT_CHAR, | 639 all_opcodes.OP_SPUT_BYTE, |
635 all_opcodes.OP_SPUT_SHORT]) | 640 all_opcodes.OP_SPUT_CHAR, |
641 all_opcodes.OP_SPUT_SHORT]) | |
642 | |
636 def redirect(opcode, args): | 643 def redirect(opcode, args): |
637 if opcode == all_opcodes.OP_NEW_INSTANCE: | 644 if opcode == all_opcodes.OP_NEW_INSTANCE: |
638 typeidx = args[1] | 645 typeidx = args[1] |
639 if typeidx in typeidxs_redir: | 646 if typeidx in typeidxs_redir: |
640 to_type = typeidxs_redir[typeidx] | 647 to_type = typeidxs_redir[typeidx] |
665 stridx = args[1] | 672 stridx = args[1] |
666 if stridx not in stridxs_redir: | 673 if stridx not in stridxs_redir: |
667 return opcode, args | 674 return opcode, args |
668 | 675 |
669 return opcode, (args[0], stridxs_redir[stridx]) | 676 return opcode, (args[0], stridxs_redir[stridx]) |
670 elif opcode in field_opcodes: | 677 elif opcode in field2_opcodes: |
671 fieldidx = args[2] | 678 fieldidx = args[2] |
672 if fieldidx not in fieldidxs_redir: | 679 if fieldidx not in fieldidxs_redir: |
673 return opcode, args | 680 return opcode, args |
674 return opcode, (args[0], args[1], fieldidxs_redir[fieldidx]) | 681 return opcode, (args[0], args[1], fieldidxs_redir[fieldidx]) |
682 elif opcode in field1_opcodes: | |
683 fieldidx = args[1] | |
684 if fieldidx not in fieldidxs_redir: | |
685 return opcode, args | |
686 return opcode, (args[0], fieldidxs_redir[fieldidx]) | |
675 return opcode, args | 687 return opcode, args |
676 | 688 |
677 new_op_vectors = [redirect(opcode, args) for opcode, args in op_vectors] | 689 new_op_vectors = [redirect(opcode, args) for opcode, args in op_vectors] |
678 new_insns_blk = encode_opcode_vectors(new_op_vectors) | 690 new_insns_blk = encode_opcode_vectors(new_op_vectors) |
679 | 691 |