Check / Set passwords for password tags

This commit is contained in:
Jindra Petřík
2015-10-26 20:41:47 +01:00
parent 75b407d119
commit 4d6dda002e
6 changed files with 359 additions and 5 deletions
@@ -19,10 +19,13 @@ package com.jpexs.decompiler.flash.tags;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.tags.base.PasswordTag;
import com.jpexs.decompiler.flash.types.BasicType;
import com.jpexs.decompiler.flash.types.annotations.Password;
import com.jpexs.decompiler.flash.types.annotations.Reserved;
import com.jpexs.decompiler.flash.types.annotations.SWFType;
import com.jpexs.helpers.ByteArrayRange;
import com.jpexs.helpers.MD5Crypt;
import java.io.IOException;
/**
@@ -30,7 +33,7 @@ import java.io.IOException;
*
* @author JPEXS
*/
public class EnableDebugger2Tag extends Tag {
public class EnableDebugger2Tag extends Tag implements PasswordTag {
public static final int ID = 64;
@@ -43,6 +46,7 @@ public class EnableDebugger2Tag extends Tag {
/**
* MD5 hash of password
*/
@Password
public String passwordHash;
/**
@@ -52,7 +56,7 @@ public class EnableDebugger2Tag extends Tag {
*/
public EnableDebugger2Tag(SWF swf) {
super(swf, ID, NAME, null);
passwordHash = "PasswordHash";
setPassword("");
}
/**
@@ -84,4 +88,14 @@ public class EnableDebugger2Tag extends Tag {
sos.writeUI16(reserved);
sos.writeString(passwordHash);
}
@Override
public void setPassword(String password) {
this.passwordHash = MD5Crypt.crypt(password, 2);
}
@Override
public boolean hasPassword(String password) {
return this.passwordHash.equals(MD5Crypt.crypt(password, 2));
}
}
@@ -19,7 +19,10 @@ package com.jpexs.decompiler.flash.tags;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.tags.base.PasswordTag;
import com.jpexs.decompiler.flash.types.annotations.Password;
import com.jpexs.helpers.ByteArrayRange;
import com.jpexs.helpers.MD5Crypt;
import java.io.IOException;
/**
@@ -27,7 +30,7 @@ import java.io.IOException;
*
* @author JPEXS
*/
public class EnableDebuggerTag extends Tag {
public class EnableDebuggerTag extends Tag implements PasswordTag {
public static final int ID = 58;
@@ -36,6 +39,7 @@ public class EnableDebuggerTag extends Tag {
/**
* MD5 hash of password
*/
@Password
public String passwordHash;
/**
@@ -45,7 +49,7 @@ public class EnableDebuggerTag extends Tag {
*/
public EnableDebuggerTag(SWF swf) {
super(swf, ID, NAME, null);
passwordHash = "PasswordHash";
setPassword("");
}
/**
@@ -77,4 +81,16 @@ public class EnableDebuggerTag extends Tag {
sos.writeString(passwordHash);
}
}
@Override
public void setPassword(String password) {
//Assuming EnableDebugger tag has same hash type as EnableDebugger2
this.passwordHash = MD5Crypt.crypt(password, 2);
}
@Override
public boolean hasPassword(String password) {
return this.passwordHash.equals(MD5Crypt.crypt(password, 2));
}
}
@@ -19,7 +19,10 @@ package com.jpexs.decompiler.flash.tags;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.tags.base.PasswordTag;
import com.jpexs.decompiler.flash.types.annotations.Password;
import com.jpexs.helpers.ByteArrayRange;
import com.jpexs.helpers.MD5Crypt;
import java.io.IOException;
/**
@@ -27,7 +30,7 @@ import java.io.IOException;
*
* @author JPEXS
*/
public class ProtectTag extends Tag {
public class ProtectTag extends Tag implements PasswordTag {
public static final int ID = 24;
@@ -36,6 +39,7 @@ public class ProtectTag extends Tag {
/**
* MD5 hash of password
*/
@Password
public String passwordHash;
/**
@@ -81,4 +85,16 @@ public class ProtectTag extends Tag {
sos.writeString(passwordHash);
}
}
@Override
public void setPassword(String password) {
//Assuming Protect tag has same hash type as EnableDebugger2
this.passwordHash = MD5Crypt.crypt(password, 2);
}
@Override
public boolean hasPassword(String password) {
return this.passwordHash.equals(MD5Crypt.crypt(password, 2));
}
}
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.tags.base;
/**
*
* @author JPEXS
*/
public interface PasswordTag {
public void setPassword(String password);
public boolean hasPassword(String password);
}
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. */
package com.jpexs.decompiler.flash.types.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Password field - it has MD5 crypted password.
*
* TODO: use this in GUI tag editor to set passwords
*
* @author JPEXS
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Password {
}