Moved blog templates to default paths
This commit is contained in:
parent
40665d78d1
commit
9c2ec8241e
55 changed files with 200 additions and 199 deletions
|
@ -25,7 +25,7 @@ _classfiles_? That would be awesome! *Spoiler alert* I did it.
|
|||
First of all, you have a _minecraft.jar_ file that it's just a packaged set of
|
||||
java compiled files, you can just `tar -xf` or `unzip` it into a folder:
|
||||
|
||||
``` text
|
||||
``` text
|
||||
unzip -qq minecraft.jar -d ./jarfile
|
||||
```
|
||||
|
||||
|
@ -36,7 +36,7 @@ source. For this purpose we're going to use [JAD](http://varaneckas.com/jad/),
|
|||
a java decompiler. With a single line of _bash_ we can look for all the .class
|
||||
files and decompile them into .java source code:
|
||||
|
||||
``` text
|
||||
``` text
|
||||
ls ./jarfile/*.class | xargs -n1 jad -sjava -dclasses &> /dev/null
|
||||
```
|
||||
|
||||
|
@ -45,19 +45,19 @@ into a separate directory. But there's a lot of files! And also, when we open
|
|||
one...
|
||||
|
||||
``` java
|
||||
public class aea extends aeb
|
||||
{
|
||||
public aea()
|
||||
{
|
||||
}
|
||||
|
||||
protected void a(long l, int i, int j, byte abyte0[], double d,
|
||||
double d1, double d2)
|
||||
{
|
||||
a(l, i, j, abyte0, d, d1, d2, 1.0F + b.nextFloat() * 6F, 0.0F, 0.0F, -1, -1, 0.5D);
|
||||
}
|
||||
// ...
|
||||
}
|
||||
public class aea extends aeb
|
||||
{
|
||||
public aea()
|
||||
{
|
||||
}
|
||||
|
||||
protected void a(long l, int i, int j, byte abyte0[], double d,
|
||||
double d1, double d2)
|
||||
{
|
||||
a(l, i, j, abyte0, d, d1, d2, 1.0F + b.nextFloat() * 6F, 0.0F, 0.0F, -1, -1, 0.5D);
|
||||
}
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
Look at that beautiful obfuscated piece of code! This is getting more
|
||||
|
@ -73,12 +73,12 @@ and get only the ones that contains the pieces of information I look for. For
|
|||
this test, I used the string "diamond":
|
||||
|
||||
``` text
|
||||
$ grep diamond ./classes/*
|
||||
./classes/bfp.java: "cloth", "chain", "iron", "diamond", "gold"
|
||||
./classes/bge.java: "cloth", "chain", "iron", "diamond", "gold"
|
||||
./classes/kd.java: w = (new kc(17, "diamonds", -1, 5, xn.p, k)).c();
|
||||
./classes/rf.java: null, "mob/horse/armor_metal.png", "mob/horse/armor_gold.png", "mob/horse/armor_diamond.png"
|
||||
./classes/xn.java: p = (new xn(8)).b("diamond").a(wh.l);
|
||||
$ grep diamond ./classes/*
|
||||
./classes/bfp.java: "cloth", "chain", "iron", "diamond", "gold"
|
||||
./classes/bge.java: "cloth", "chain", "iron", "diamond", "gold"
|
||||
./classes/kd.java: w = (new kc(17, "diamonds", -1, 5, xn.p, k)).c();
|
||||
./classes/rf.java: null, "mob/horse/armor_metal.png", "mob/horse/armor_gold.png", "mob/horse/armor_diamond.png"
|
||||
./classes/xn.java: p = (new xn(8)).b("diamond").a(wh.l);
|
||||
./classes/xn.java: cg = (new xn(163)).b("horsearmordiamond").d(1).a(wh.f);
|
||||
```
|
||||
|
||||
|
@ -89,7 +89,7 @@ another keyword: _flintAndSteel_, works great here, but in a real example you
|
|||
will need to use more than one keyword to look for data.
|
||||
|
||||
``` text
|
||||
$ grep flintAndSteel ./classes/*
|
||||
$ grep flintAndSteel ./classes/*
|
||||
./classes/xn.java: public static xn k = (new xh(3)).b("flintAndSteel");
|
||||
```
|
||||
|
||||
|
@ -110,15 +110,15 @@ After some tests, I decided to _convert_ the java code into python. For that,
|
|||
I used simple find and match to get the lines that had the definitions I
|
||||
wanted, something line this:
|
||||
|
||||
``` java
|
||||
// As a first simple filter, we only use a code line if a double quote is found on it.
|
||||
// Then, regex: /new (?P<code>[a-z]{2}\((?P<id>[1-9]{1,3}).*\"(?P<name>\w+)\"\))/
|
||||
// ...
|
||||
T = (new xm(38, xo.e)).b("hoeGold");
|
||||
U = (new yi(39, aqh.aD.cE, aqh.aE.cE)).b("seeds");
|
||||
V = (new xn(40)).b("wheat").a(wh.l);
|
||||
X = (vr)(new vr(42, vt.a, 0, 0)).b("helmetCloth");
|
||||
Y = (vr)(new vr(43, vt.a, 0, 1)).b("chestplateCloth");
|
||||
``` java
|
||||
// As a first simple filter, we only use a code line if a double quote is found on it.
|
||||
// Then, regex: /new (?P<code>[a-z]{2}\((?P<id>[1-9]{1,3}).*\"(?P<name>\w+)\"\))/
|
||||
// ...
|
||||
T = (new xm(38, xo.e)).b("hoeGold");
|
||||
U = (new yi(39, aqh.aD.cE, aqh.aE.cE)).b("seeds");
|
||||
V = (new xn(40)).b("wheat").a(wh.l);
|
||||
X = (vr)(new vr(42, vt.a, 0, 0)).b("helmetCloth");
|
||||
Y = (vr)(new vr(43, vt.a, 0, 1)).b("chestplateCloth");
|
||||
// ...
|
||||
```
|
||||
|
||||
|
@ -130,34 +130,34 @@ Since that java code is not python evaluable, just convert it:
|
|||
- Converted arguments to string. This can be improved a lot, leaving decimals, converting floats to python notation, detecting words for string conversion, etc. Since for now I am not using any of the extra parameters this works for me.
|
||||
- Be careful with reserved python names! (`and`, `all`, `abs`, ...)
|
||||
|
||||
``` python
|
||||
// Java: U = (new yi(39, aqh.aD.cE, aqh.aE.cE)).b("seeds");
|
||||
yi("39", "aqh.ad.cE", "aqh.aE.cE").b("seeds")
|
||||
// Java: bm = (new xi(109, 2, 0.3F, true)).a(mv.s.H, 30, 0, 0.3F).b("chickenRaw");
|
||||
``` python
|
||||
// Java: U = (new yi(39, aqh.aD.cE, aqh.aE.cE)).b("seeds");
|
||||
yi("39", "aqh.ad.cE", "aqh.aE.cE").b("seeds")
|
||||
// Java: bm = (new xi(109, 2, 0.3F, true)).a(mv.s.H, 30, 0, 0.3F).b("chickenRaw");
|
||||
xi("109", "2", "0.3F", "true").a("mv.s.H", "30", "0", "0.3F").b("chickenRaw")
|
||||
```
|
||||
|
||||
Now I defined an object to match with the java code definitions when
|
||||
evaluating:
|
||||
|
||||
``` python
|
||||
class GameItem(object):
|
||||
def __init__(self, game_id, *args):
|
||||
self.id = int(game_id)
|
||||
|
||||
def __str__(self, *args):
|
||||
return "<Item(%d: '%s')>" % (
|
||||
self.id,
|
||||
self.name
|
||||
)
|
||||
|
||||
def method(self, *args):
|
||||
if len(args) == 1 and isinstance(args[0], str):
|
||||
"Sets the name"
|
||||
self.name = args[0]
|
||||
return self
|
||||
|
||||
def __getattr__(self, *args):
|
||||
``` python
|
||||
class GameItem(object):
|
||||
def __init__(self, game_id, *args):
|
||||
self.id = int(game_id)
|
||||
|
||||
def __str__(self, *args):
|
||||
return "<Item(%d: '%s')>" % (
|
||||
self.id,
|
||||
self.name
|
||||
)
|
||||
|
||||
def method(self, *args):
|
||||
if len(args) == 1 and isinstance(args[0], str):
|
||||
"Sets the name"
|
||||
self.name = args[0]
|
||||
return self
|
||||
|
||||
def __getattr__(self, *args):
|
||||
return self.method
|
||||
```
|
||||
|
||||
|
@ -171,19 +171,19 @@ the class name _<insert obfuscated class name here>_ is not defined.
|
|||
With that, we will declare that name as an instance of the GameItem class, so
|
||||
re-evaluating the code again will return a GameItem object:
|
||||
|
||||
``` python
|
||||
try:
|
||||
# Tries to evaluate the piece of code that we converted
|
||||
obj = eval(item['code'])
|
||||
except NameError as error:
|
||||
# Class name do not exist! We need to define it.
|
||||
# Extract class name from the error message
|
||||
# Defined somewhere else: class_error_regex = re.compile('name \'(?P<name>\w+)\' is not defined')
|
||||
class_name = class_error_regex.search(error.__str__()).group('name')
|
||||
# Define class name as instance of GameItem
|
||||
setattr(sys.modules[__name__], class_name, type(class_name, (GameItem,), {}))
|
||||
# Evaluate again to get the object
|
||||
obj = eval(item['code'])
|
||||
``` python
|
||||
try:
|
||||
# Tries to evaluate the piece of code that we converted
|
||||
obj = eval(item['code'])
|
||||
except NameError as error:
|
||||
# Class name do not exist! We need to define it.
|
||||
# Extract class name from the error message
|
||||
# Defined somewhere else: class_error_regex = re.compile('name \'(?P<name>\w+)\' is not defined')
|
||||
class_name = class_error_regex.search(error.__str__()).group('name')
|
||||
# Define class name as instance of GameItem
|
||||
setattr(sys.modules[__name__], class_name, type(class_name, (GameItem,), {}))
|
||||
# Evaluate again to get the object
|
||||
obj = eval(item['code'])
|
||||
```
|
||||
|
||||
And with this, getting data from source code was possible and really helpful.
|
||||
|
@ -210,4 +210,4 @@ github.
|
|||
---
|
||||
pub_date: 2013-07-04
|
||||
---
|
||||
_template: blog/post.html
|
||||
_template: blog-post.html
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue