refine for pirates obfuscation

This commit is contained in:
David Rose 2006-08-16 00:20:57 +00:00
parent 9db4c26abb
commit fe034278e3
13 changed files with 121 additions and 31 deletions

View File

@ -18,7 +18,7 @@
#define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx
#define SOURCES \
dcAtomicField.h dcClass.h dcClass.I \
dcAtomicField.h dcAtomicField.I dcClass.h dcClass.I \
dcDeclaration.h \
dcField.h dcField.I \
dcFile.h dcFile.I \

View File

@ -0,0 +1,18 @@
// Filename: dcAtomicField.I
// Created by: drose (15Aug06)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// panda3d-general@lists.sourceforge.net .
//
////////////////////////////////////////////////////////////////////

View File

@ -30,7 +30,11 @@
// Description:
////////////////////////////////////////////////////////////////////
DCAtomicField::
DCAtomicField(const string &name, DCClass *dclass) : DCField(name, dclass) {
DCAtomicField(const string &name, DCClass *dclass,
bool bogus_field) :
DCField(name, dclass)
{
_bogus_field = bogus_field;
}
////////////////////////////////////////////////////////////////////

View File

@ -37,7 +37,7 @@
////////////////////////////////////////////////////////////////////
class EXPCL_DIRECT DCAtomicField : public DCField {
public:
DCAtomicField(const string &name, DCClass *dclass);
DCAtomicField(const string &name, DCClass *dclass, bool bogus_field);
virtual ~DCAtomicField();
PUBLISHED:
@ -53,7 +53,7 @@ PUBLISHED:
string get_element_name(int n) const;
DCSubatomicType get_element_type(int n) const;
int get_element_divisor(int n) const;
public:
void add_element(DCParameter *element);
@ -74,4 +74,6 @@ private:
Elements _elements;
};
#include "dcAtomicField.I"
#endif

View File

@ -290,7 +290,8 @@ get_num_inherited_fields() const {
if (_inherited_fields.empty()) {
((DCClass *)this)->rebuild_inherited_fields();
}
nassertr(!_inherited_fields.empty(), 0);
nassertr(is_bogus_class() || !_inherited_fields.empty(), 0);
return (int)_inherited_fields.size();
} else {
@ -343,6 +344,30 @@ get_inherited_field(int n) const {
}
}
////////////////////////////////////////////////////////////////////
// Function : DCClass::inherits_from_bogus_class
// Access : Published
// Description : Returns true if this class, or any class in the
// inheritance heirarchy for this class, is a "bogus"
// class--a forward reference to an as-yet-undefined
// class.
////////////////////////////////////////////////////////////////////
bool DCClass::
inherits_from_bogus_class() const {
if (is_bogus_class()) {
return true;
}
Parents::const_iterator pi;
for (pi = _parents.begin(); pi != _parents.end(); ++pi) {
if ((*pi)->inherits_from_bogus_class()) {
return true;
}
}
return false;
}
////////////////////////////////////////////////////////////////////
// Function : DCClass::output
// Access : Published, Virtual
@ -1190,21 +1215,23 @@ write(ostream &out, bool brief, int indent_level) const {
Fields::const_iterator fi;
for (fi = _fields.begin(); fi != _fields.end(); ++fi) {
(*fi)->write(out, brief, indent_level + 2);
if (!(*fi)->is_bogus_field()) {
(*fi)->write(out, brief, indent_level + 2);
/*
if (true || (*fi)->has_default_value()) {
indent(out, indent_level + 2) << "// = ";
DCPacker packer;
packer.set_unpack_data((*fi)->get_default_value());
packer.begin_unpack(*fi);
packer.unpack_and_format(out, false);
if (!packer.end_unpack()) {
out << "<error>";
/*
if (true || (*fi)->has_default_value()) {
indent(out, indent_level + 2) << "// = ";
DCPacker packer;
packer.set_unpack_data((*fi)->get_default_value());
packer.begin_unpack(*fi);
packer.unpack_and_format(out, false);
if (!packer.end_unpack()) {
out << "<error>";
}
out << "\n";
}
out << "\n";
*/
}
*/
}
indent(out, indent_level) << "};\n";
@ -1247,8 +1274,10 @@ output_instance(ostream &out, bool brief, const string &prename,
Fields::const_iterator fi;
for (fi = _fields.begin(); fi != _fields.end(); ++fi) {
(*fi)->output(out, brief);
out << "; ";
if (!(*fi)->is_bogus_field()) {
(*fi)->output(out, brief);
out << "; ";
}
}
out << "}";

View File

@ -80,6 +80,7 @@ PUBLISHED:
INLINE bool is_struct() const;
INLINE bool is_bogus_class() const;
bool inherits_from_bogus_class() const;
INLINE void start_generate();
INLINE void stop_generate();

View File

@ -68,6 +68,20 @@ get_default_value() const {
return _default_value;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::is_bogus_field
// Access: Published
// Description: Returns true if the field has been flagged as a bogus
// field. This is set for fields that are generated by
// the parser as placeholder for missing fields, as
// when reading a partial file; it should not occur in a
// normal valid dc file.
////////////////////////////////////////////////////////////////////
INLINE bool DCField::
is_bogus_field() const {
return _bogus_field;
}
////////////////////////////////////////////////////////////////////
// Function: DCField::is_required
// Access: Published

View File

@ -41,8 +41,10 @@ DCField() :
#endif
{
_number = -1;
_has_default_value = false;
_default_value_stale = true;
_has_default_value = false;
_bogus_field = false;
_has_nested_fields = true;
_num_nested_fields = 0;
@ -185,11 +187,11 @@ as_parameter() const {
// consumption. Returns empty string if there is an error.
////////////////////////////////////////////////////////////////////
string DCField::
format_data(const string &packed_data) {
format_data(const string &packed_data, bool show_field_names) {
DCPacker packer;
packer.set_unpack_data(packed_data);
packer.begin_unpack(this);
string result = packer.unpack_and_format(true);
string result = packer.unpack_and_format(show_field_names);
if (!packer.end_unpack()) {
return string();
}

View File

@ -60,7 +60,7 @@ PUBLISHED:
virtual DCParameter *as_parameter();
virtual const DCParameter *as_parameter() const;
string format_data(const string &packed_data);
string format_data(const string &packed_data, bool show_field_names = true);
string parse_string(const string &formatted_string);
bool validate_ranges(const string &packed_data) const;
@ -68,6 +68,8 @@ PUBLISHED:
INLINE bool has_default_value() const;
INLINE const string &get_default_value() const;
INLINE bool is_bogus_field() const;
INLINE bool is_required() const;
INLINE bool is_broadcast() const;
INLINE bool is_ram() const;
@ -111,6 +113,7 @@ protected:
int _number;
bool _default_value_stale;
bool _has_default_value;
bool _bogus_field;
private:
string _default_value;

View File

@ -30,6 +30,7 @@
////////////////////////////////////////////////////////////////////
DCMolecularField::
DCMolecularField(const string &name, DCClass *dclass) : DCField(name, dclass) {
_got_keywords = false;
}
////////////////////////////////////////////////////////////////////
@ -94,8 +95,12 @@ get_atomic(int n) const {
////////////////////////////////////////////////////////////////////
void DCMolecularField::
add_atomic(DCAtomicField *atomic) {
if (_fields.empty()) {
copy_keywords(*atomic);
if (!atomic->is_bogus_field()) {
if (!_got_keywords) {
// The first non-bogus atomic field determines our keywords.
copy_keywords(*atomic);
_got_keywords = true;
}
}
_fields.push_back(atomic);

View File

@ -61,6 +61,7 @@ private:
// definition as read from the file.
typedef pvector<DCAtomicField *> Fields;
Fields _fields;
bool _got_keywords;
DCParameter *get_next_pack_element();

View File

@ -488,9 +488,9 @@ atomic_field:
if (current_class == (DCClass *)NULL) {
yyerror("Cannot define a method outside of a struct or class.");
DCClass *temp_class = new DCClass(dc_file, "temp", false, false); // memory leak.
current_atomic = new DCAtomicField($1, temp_class);
current_atomic = new DCAtomicField($1, temp_class, false);
} else {
current_atomic = new DCAtomicField($1, current_class);
current_atomic = new DCAtomicField($1, current_class, false);
}
}
parameter_list ')'
@ -1190,7 +1190,18 @@ atomic_name:
DCField *field = current_class->get_field_by_name($1);
$$ = (DCAtomicField *)NULL;
if (field == (DCField *)NULL) {
yyerror("Unknown field: " + $1);
// Maybe the field is unknown because the class is partially
// bogus. In that case, allow it for now; create a bogus field as
// a placeholder.
if (current_class->inherits_from_bogus_class()) {
$$ = new DCAtomicField($1, current_class, true);
current_class->add_field($$);
} else {
// Nope, it's a fully-defined class, so this is a real error.
yyerror("Unknown field: " + $1);
}
} else {
$$ = field->as_atomic_field();
if ($$ == (DCAtomicField *)NULL) {
@ -1211,7 +1222,7 @@ molecular_atom_list:
{
if ($3 != (DCAtomicField *)NULL) {
current_molecular->add_atomic($3);
if (!current_molecular->compare_keywords(*$3)) {
if (!$3->is_bogus_field() && !current_molecular->compare_keywords(*$3)) {
yyerror("Mismatched keywords in molecule between " +
current_molecular->get_atomic(0)->get_name() + " and " +
$3->get_name());

View File

@ -402,7 +402,7 @@ output_instance(ostream &out, bool brief, const string &prename,
last_fields->output(out, brief);
}
last_fields = dcase->_fields;
out << "case " << _key_parameter->format_data(dcase->_value) << ": ";
out << "case " << _key_parameter->format_data(dcase->_value, false) << ": ";
}
if (_default_case != (SwitchFields *)NULL) {
@ -451,7 +451,7 @@ write_instance(ostream &out, bool brief, int indent_level,
}
last_fields = dcase->_fields;
indent(out, indent_level)
<< "case " << _key_parameter->format_data(dcase->_value) << ":\n";
<< "case " << _key_parameter->format_data(dcase->_value, false) << ":\n";
}
if (_default_case != (SwitchFields *)NULL) {