Example usage for org.aspectj.lang ProceedingJoinPoint getThis

List of usage examples for org.aspectj.lang ProceedingJoinPoint getThis

Introduction

In this page you can find the example usage for org.aspectj.lang ProceedingJoinPoint getThis.

Prototype

Object getThis();

Source Link

Document

Returns the currently executing object.

Usage

From source file:com.rover12421.shaka.apktool.lib.AndrolibResourcesAj.java

License:Apache License

/**
 * png?// ww  w.j a  v a  2 s .  c  o  m
 * brut.androlib.res.AndrolibResources
 * public void aaptPackage(File apkFile, File manifest, File resDir, File rawDir, File assetDir, File[] include)
 */
@Around("execution(* brut.androlib.res.AndrolibResources.aaptPackage(..))"
        + "&& args(apkFile, manifest, resDir, rawDir, assetDir, include)")
public void aaptPackage_around(ProceedingJoinPoint joinPoint, File apkFile, File manifest, File resDir,
        File rawDir, File assetDir, File[] include) throws Throwable {

    AndrolibResources thiz = (AndrolibResources) joinPoint.getThis();
    doNotCompress_in_aapt_fix(thiz);

    /**
     * ?10,?
     */
    int max = 10;
    PrintStream olderr = System.err;
    String lastErrInfo = null;
    while (max-- > 0) {

        try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos)) {
            System.setErr(ps);
            try {
                joinPoint.proceed(joinPoint.getArgs());
                System.setErr(olderr);
                /**
                 * ????
                 */
                fuckNotDefinedRes_clearAddRes(apkFile);
                break;
            } catch (Throwable e) {
                System.setErr(olderr);

                String errStr = new String(baos.toByteArray());

                /**
                 * ?,?,
                 */
                if (errStr.equals(lastErrInfo)) {
                    throw new ShakaException(errStr, e);
                }
                lastErrInfo = errStr;

                boolean bContinue = false;
                if (manifest != null) {
                    String rootDir = manifest.getParentFile().getAbsolutePath();

                    if (checkPng(errStr, rootDir)) {
                        bContinue = true;
                    }

                    if (horizontalScrollView_check(errStr)) {
                        bContinue = true;
                    }

                    if (!bContinue) {
                        //????,????
                        bContinue = fuckNotDefinedRes(errStr, rootDir);
                    }
                }

                if (!bContinue) {
                    throw new ShakaException(errStr, e);
                }
            } finally {
                System.setErr(olderr);
            }
        }
    }

}

From source file:com.rover12421.shaka.apktool.lib.ARSCDecoderAj.java

License:Apache License

@Around("execution(* brut.androlib.res.decoder.ARSCDecoder.readTableHeader())")
public ResPackage[] readTableHeader(ProceedingJoinPoint joinPoint) throws Exception {
    ARSCDecoder decoder = (ARSCDecoder) joinPoint.getThis();
    ExtDataInput mIn = decoder.getIn();//from   w  w  w  . j a v a 2  s  . co  m

    //        nextChunkCheckType(ARSCDecoder.Header.TYPE_TABLE);
    decoder.nextChunkCheckType0(ARSCDecoder.Header.TYPE_TABLE);
    int packageCount = mIn.readInt();

    try {
        ARSCDecoder.Header header = decoder.getHeader();
        if (header.headerSize > ResTable_header_SIZE) {
            int skip = header.headerSize - ResTable_header_SIZE;
            LogHelper
                    .warning("ResChunk_header exception : read size = " + header.headerSize + ", skip " + skip);
            mIn.skipBytes(skip);
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }

    StringBlock mTableStrings = StringBlock.read(mIn);
    decoder.setTableStrings(mTableStrings);

    ResPackage[] packages = new ResPackage[packageCount];

    //        nextChunk();
    decoder.nextChunk0();

    for (int i = 0; i < packageCount; i++) {
        //            packages[i] = readTablePackage();
        packages[i] = decoder.readTablePackage0();
    }
    return packages;
}

From source file:com.rover12421.shaka.apktool.lib.ARSCDecoderAj.java

License:Apache License

@Around("execution(* brut.androlib.res.decoder.ARSCDecoder.readValue())")
public ResIntBasedValue readValue(ProceedingJoinPoint joinPoint) throws Exception {
    ARSCDecoder decoder = (ARSCDecoder) joinPoint.getThis();
    ExtDataInput mIn = decoder.getIn();/*  w  ww  .j a  v a 2s  .  c  o  m*/
    ResPackage mPkg = decoder.getPkg();

    /* size */mIn.skipCheckShort((short) 8);
    /* zero */mIn.skipCheckByte((byte) 0);
    byte type = mIn.readByte();
    int data = mIn.readInt();

    ResTypeSpec mTypeSpec = decoder.getTypeSpec();
    StringBlock stringBlock = decoder.getTableStrings();

    return type == TypedValue.TYPE_STRING
            //                ? mPkg.getValueFactory().factory(mTableStrings(decoder).getHTML(data), data)
            ? ResValueFactoryAj.factory(mTypeSpec, stringBlock.getHTML(data), data)
            : mPkg.getValueFactory().factory(type, data, null);
}

From source file:com.rover12421.shaka.apktool.lib.AXmlResourceParserAj.java

License:Apache License

@Around("execution(* brut.androlib.res.decoder.AXmlResourceParser.getAttributeNamespace(..))"
        + "&& args(index)")
public String getAttributeNamespace(ProceedingJoinPoint joinPoint, int index) {
    AXmlResourceParser parser = (AXmlResourceParser) joinPoint.getThis();

    int offset = parser.getAttributeOffset0(index);
    int namespace = parser.getAttributes()[offset + ATTRIBUTE_IX_NAMESPACE_URI];
    if (namespace == -1) {
        return "";
    }/*from   w  w w.ja v  a  2  s  . c o m*/

    String value = parser.getStrings0().getString(namespace);
    if (value == null || value.isEmpty()) {
        int resId = parser.getAttributeNameResource(index);
        if (resId > 0) {
            value = android_ns;
            int depth = parser.getDepth();
            try {
                int nameSpaceCount = parser.getNamespaceCount(depth);
                if (nameSpaceCount == 0) {
                    // ??,???
                    value = "";
                } else if (nameSpaceCount == 1) {
                    // ???,??
                    value = parser.getNamespaceUri(0);
                } else {
                    int packageId = (resId >> 24) & 0xFF;
                    if (packageId >= 0x7f) { //??,???
                        // ,"android"??, ??
                        if (nameSpaceCount == 2) {
                            // ??"android"??
                            value = parser.getNamespaceUri(0);
                            if (value.equalsIgnoreCase(android_ns)) {
                                value = parser.getNamespaceUri(1);
                            }
                        } else {
                            // ,???
                            LogHelper.warning("Namespace quantities greater than 2, "
                                    + "may not select the correct namespace, "
                                    + "attempt to automatically select. 0x" + Integer.toHexString(resId));
                            String pkg_ns = "http://schemas.android.com/apk/res/" + Global.getPackageName();
                            for (int i = 0; i < nameSpaceCount; i++) {
                                String ns = parser.getNamespaceUri(i);
                                if (ns.equalsIgnoreCase("http://schemas.android.com/apk/res-auto")
                                        || ns.equalsIgnoreCase(pkg_ns)) {
                                    value = ns;
                                    break;
                                }
                            }
                        }
                    }
                }
            } catch (XmlPullParserException e) {
                e.printStackTrace();
            }
        } else {
            value = "";
        }
    }

    return value;
}

From source file:com.rover12421.shaka.apktool.lib.AXmlResourceParserAj.java

License:Apache License

@Around("execution(* brut.androlib.res.decoder.AXmlResourceParser.getAttributeName(..))" + "&& args(index)")
public String getAttributeName(ProceedingJoinPoint joinPoint, int index) {
    AXmlResourceParser parser = (AXmlResourceParser) joinPoint.getThis();
    String value = null;//from ww  w . j  av a 2 s.  co m
    try {
        value = parser.getAttrDecoder().decodeManifestAttr(parser.getAttributeNameResource(index));
    } catch (AndrolibException e) {
    }

    if (value == null) {
        int offset = parser.getAttributeOffset0(index);
        int name = parser.getAttributes()[offset + ATTRIBUTE_IX_NAME];
        if (name == -1) {
            value = "";
        } else {
            value = parser.getStrings0().getString(name);
        }
    } else {
        String newName = "";
        int offset = parser.getAttributeOffset0(index);
        int name = parser.getAttributes()[offset + ATTRIBUTE_IX_NAME];
        if (name != -1) {
            newName = parser.getStrings0().getString(name);
        }

        if (newName.trim().length() > 0 && !value.equals(newName) && !newName.equals("name")) {
            if (ShakaDecodeOption.getInstance().isXmlAttributeNameCorrect()) {
                LogHelper.warning("Xml attribute name correct : " + value + " to " + newName);
                int resId = parser.getAttributeNameResource(index);
                if (resId > 0) {
                    ResResSpec spec = ResTypeSpecAj.AllSpecs.get(resId);
                    if (spec != null && spec.getName().equals(value)) {
                        try {
                            ResResSpecAj.setName(spec, newName);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
                if (value.startsWith(ResTypeAj.MultipleSpec_Perfix)) {
                    try {
                        // ResConfigAj.MultipleSpec_Perfix0xId
                        String mId = value.substring(ResTypeAj.MultipleSpec_Perfix.length() + 2);
                        int id = Integer.parseInt(mId, 16);
                        ResResSpec spec = ResTypeSpecAj.AllSpecs.get(id);
                        if (spec != null && spec.getName().equals(value)) {
                            ResResSpecAj.setName(spec, newName);
                        }
                    } catch (Throwable e) {
                        e.printStackTrace();
                    }
                }
                value = newName;
            } else {
                // ?,??
                LogHelper.info(
                        "You can use [-xn|--xml-attribute-name-correct] parameter to correct the xml attribute name : "
                                + value + " to " + newName);
            }
        }

    }
    return value;
}

From source file:com.rover12421.shaka.apktool.lib.ResFileValueAj.java

License:Apache License

@Around("execution(* brut.androlib.res.data.value.ResFileValue.getStrippedPath())")
public String getStrippedPath(ProceedingJoinPoint joinPoint) {
    try {/*from  w  w w .ja  va  2 s  .c  o m*/
        return (String) joinPoint.proceed(joinPoint.getArgs());
    } catch (Throwable throwable) {
        //?res,
        //"/"?,???,?
        return "/" + ((ResFileValue) joinPoint.getThis()).getPath();
    }
}

From source file:com.rover12421.shaka.apktool.lib.ResPackageAj.java

License:Apache License

@Around("execution(* brut.androlib.res.data.ResPackage.getResSpec(..))" + "&& args(resID)")
public ResResSpec getResSpec(ProceedingJoinPoint joinPoint, ResID resID) throws Throwable {
    try {/* w  w w.  j av  a 2 s  .  c  om*/
        return (ResResSpec) joinPoint.proceed(joinPoint.getArgs());
    } catch (UndefinedResObject e) {
        if (ShakaDecodeOption.getInstance().isFuckUnkownId()) {
            ResPackage thiz = (ResPackage) joinPoint.getThis();
            return new ResResSpec(resID, String.format("[%08x]", resID.id), thiz,
                    new ResTypeSpec("FuckUnkownId", thiz.getResTable(), thiz, (byte) (resID.id & 0xFF), 0));
        } else {
            throw e;
        }
    }
}

From source file:com.rover12421.shaka.apktool.lib.ResStyleValueAj.java

License:Apache License

/**
 * package brut.androlib.res.data.value//from   ww  w  .  j  av a 2 s  . com
 * public class ResStyleValue extends ResBagValue implements ResValuesXmlSerializable
 * public void serializeToResValuesXml(XmlSerializer serializer,ResResource res)
 *
        
 <B>com.carrot.carrotfantasy.apk</B>
        
 Exception in thread "main" java.lang.ClassCastException: brut.androlib.res.data.value.ResStyleValue cannot be cast to brut.androlib.res.data.value.ResAttr
 at brut.androlib.res.data.value.ResStyleValue.serializeToResValuesXml(ResStyleValue.java:65)
 at brut.androlib.res.AndrolibResources.generateValuesFile(AndrolibResources.java:564)
 at brut.androlib.res.AndrolibResources.decode(AndrolibResources.java:327)
 at brut.androlib.Androlib.decodeResourcesFull(Androlib.java:123)
 at brut.androlib.ApkDecoder.decode(ApkDecoder.java:102)
 at brut.apktool.Main.cmdDecode(Main.java:170)
 at brut.apktool.Main.main(Main.java:86)
        
 */
@Around("execution(void brut.androlib.res.data.value.ResStyleValue.serializeToResValuesXml(..))"
        + "&& args(serializer, res)")
public void serializeToResValuesXml(ProceedingJoinPoint joinPoint, XmlSerializer serializer, ResResource res)
        throws IOException, AndrolibException {
    try {
        ResStyleValue thiz = (ResStyleValue) joinPoint.getThis();
        ResReferenceValue mParent = thiz.getParent();
        Duo<ResReferenceValue, ResScalarValue>[] mItems = (Duo<ResReferenceValue, ResScalarValue>[]) thiz
                .getItems();
        serializer.startTag(null, "style");
        serializer.attribute(null, "name", res.getResSpec().getName());
        if (!mParent.isNull() && !mParent.referentIsNull()) {
            serializer.attribute(null, "parent", mParent.encodeAsResXmlAttr());
        } else if (res.getResSpec().getName().indexOf('.') != -1) {
            serializer.attribute(null, "parent", "");
        }
        for (int i = 0; i < mItems.length; i++) {
            ResResSpec spec = mItems[i].m1.getReferent();
            String name;
            String value = null;

            String resource = spec.getDefaultResource().getValue().toString();
            // hacky-fix remove bad ReferenceVars
            if (resource.contains("ResReferenceValue@")) {
                continue;
            } else if (resource.contains("ResStringValue@")) {
                name = "@" + spec.getFullName(res.getResSpec().getPackage(), false);
            } else {
                //                    ResAttr attr = (ResAttr) spec.getDefaultResource().getValue();
                ResValue resValue = spec.getDefaultResource().getValue();
                if (!(resValue instanceof ResAttr)) {
                    //
                    continue;
                }
                ResAttr attr = (ResAttr) resValue;
                value = attr.convertToResXmlFormat(mItems[i].m2);
                name = spec.getFullName(res.getResSpec().getPackage(), true);
            }

            if (value == null) {
                value = mItems[i].m2.encodeAsResXmlValue();
            }

            if (value == null) {
                continue;
            }

            serializer.startTag(null, "item");
            serializer.attribute(null, "name", name);
            serializer.text(value);
            serializer.endTag(null, "item");
        }
        serializer.endTag(null, "style");
    } catch (Throwable e) {
        e.printStackTrace();
    }
}

From source file:com.rover12421.shaka.apktool.lib.ResTypeSpecAj.java

License:Apache License

@Around("execution(* brut.androlib.res.data.ResTypeSpec.addResSpec(..))" + "&& args(spec)")
public void addResSpec(ProceedingJoinPoint joinPoint, ResResSpec spec) throws Throwable {
    ResTypeSpec thiz = (ResTypeSpec) joinPoint.getThis();

    addAllResResSpec(spec);/*www  .  j a  va 2s .co  m*/

    ResResSpec exitsSpec = null;
    try {
        exitsSpec = thiz.getResSpec(spec.getName());
    } catch (Exception e) {
    }

    if (exitsSpec == null) {
        joinPoint.proceed(joinPoint.getArgs());
    } else {
        LogHelper.warning(String.format("Multiple res specs: %s/%s", thiz.getName(), spec.getName()));
        if (exitsSpec.getId() != spec.getId()) {
            addMultipleResResSpec(spec);
            addMultipleResResSpec(exitsSpec);
        }
    }
}

From source file:com.rover12421.shaka.apktool.lib.StringBlockAj.java

License:Apache License

@Around("execution(* brut.androlib.res.decoder.StringBlock.getStyle(..))" + "&& args(index)")
public int[] getStyle(ProceedingJoinPoint joinPoint, int index) throws Throwable {
    StringBlock thiz = (StringBlock) joinPoint.getThis();
    int[] m_styleOffsets = thiz.getStyleOffsets();
    int[] m_styles = thiz.getStyles();
    if (m_styleOffsets == null || m_styles == null || index >= m_styleOffsets.length) {
        return null;
    }// w  ww.  j  a va2  s . co m
    int offset = m_styleOffsets[index] / 4;
    if (offset < 0 || offset > m_styles.length) {
        return null;
    }
    return (int[]) joinPoint.proceed(joinPoint.getArgs());
}