RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Reverse Engineering.

0 Members and 1 Guest are viewing this topic.

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind
You may have heard the term Reverse Engineering before. Often you see it in EULAs for software products when they tell you not to Reverse Engineer their product..
Here is an exercise in Reverse Engineering.
In the EULAs they normally mean the reverse engineering is extracting the code from the binaries into some high level language. Could for instance be Ruby.
In this case I give you the badly structured code for a high level language (Ruby) and want you to reverse engineer it to the model level.
Well... Basically I just want you to understand what it does.
This exercise will probably make you understand why I don't like it very much. At least not in this form
Spoiler for Could potentially scar your eyes. I'll kick anyone who made code like this in practice >8U:
Code: [Select]
$: << './lib/';require 'singleton.rb'
module Graphics;class << self;alias m_bb update end;def self.update;self.m_bb; M.bb
end;end;module M;class A;def A.e_c(b);if b.is_a?(Bitmap);c = b;elsif b.is_a?(File)
c = Bitmap.new(b.path);elsif b.is_a?(String);if File.exists?(b)
c = Bitmap.new(b);else;c = Bitmap.new(32,32);end;else;c = Bitmap.new(32,32)
end;return c;rescue StandardError => err;return Bitmap.new(32,32);end
def A.e_d_b(d_id, f = false);if d_id.is_a?(Integer);if f;d = $data_enemies[d_id]
else;d = $game_actors[d_id];end;c = RPG::Cache.dacter(d.character_name, d.character_hue) :mad:
else;c = RPG::Cache.dacter(d_id.character_name, d_id.character_hue);end
raise "No dacter c error" if !c.is_a?(Bitmap);return c;rescue StandardError => err
return Bitmap.new(32,32);end;end;class << self;def bb;G.bb;end;def q(*mm, &block)
G.q(*mm, &block);end;end;class G;@@next_auto_nb = 0;include Singleton
ICM =["bb", "remove_all", "non", "q", "qPair", "qDefault", "qnb","e_object","m"]
ICM.each {|val|eval("def self.#{val}(*mm, &block) instance.#{val}(*mm,&block); end")}
def initialize;@l_h = [];@l_i = [];@l_j = [];@l_k = [];@o = Graphics.frame_count
@m = N.new;end;def q(*mm, &block);aa = nil;if block.is_a?(Proc);aa = block.call
end;aa.downcase! if aa.is_a?(String);case aa;when 'par' then qPair(*mm)
when 'nb' then qnb(*mm);else qDefault(*mm);end;end;def qPair(*mm);mm.flatten!
return false if mm.size % 2 == 1;for i in mm.size / 2;qnb(mm[i*2], mm[i*2+1])
end;return true;end;def qDefault(*mm);qnb(@@next_auto_nb, *mm);@@next_auto_nb += 1
return @@next_auto_nb - 1;end;def qnb(nb, *mm);mm.flatten!;for ml in mm
if ml.is_a?(Ab);q_object(ml,'Ab',nb);elsif ml.is_a?(Ag)
q_object(ml,'Ag',nb);elsif ml.is_a?(Af);q_object(ml,'Af',nb)
else;end;end;end;def q_object(object, type, nb = nil)
unless object.is_a?(eval(type.capitalize));return false;end;
unless eval("@nb_#{type.downcase}s.is_a?(Hash)");eval("@nb_#{type.downcase}s = {}")
mn = eval("@nb_#{type.downcase}s");mn[nb] = object;return true;end
mn =eval("@nb_#{type.downcase}s");if mn[nb].is_a?(Array);
return false if mn[nb].include?(object);mn[nb] << object;return true
end;mn[nb] = [mn[nb], object];return true;end;def e_object(type, nb)
unless eval("@nb_#{type.downcase}s.is_a?(Hash)");return nil;end
return eval("@nb_#{type.downcase}s[nb]");end;def m;return @m;end;def bb
fc = Graphics.frame_count;return if fc < @o + 1;@o = fc;@m.bb;@l_j.each {|x| x.bb}
end;def reset;initialize;for variable in instance_variables
unless (variable =~ /@nb_.*s/).nil?;remove_instance_variable variable;end;end
end;def remove_all;@l_j.each {|af| af.dispose};@l_i.each {|ag| ag.dispose}
@l_h.each {|ab| ab.dispose};@m.clear;reset;end;def non(obj)
if obj.is_a?(Ab);@l_h << obj unless @l_h.include?(obj);elsif obj.is_a?(Ag)
@l_i << obj unless @l_i.include?(obj);elsif obj.is_a?(Af);@l_j << obj unless @l_j.include?(obj)
elsif obj.is_a?(Ao);@l_k << obj unless @l_k.include?(obj);end;end;end;class N
attr_reader :bfs, :tps;def initialize;@tps = 40;@last_bf = 0.0;@m = {}
@bfs = 0;@vv = [];end;def tps=(number);return false unless number.is_a?(Numeric)
@tps = number;return true;end;def q(ag, pos=0);return false unless ag.is_a?(Ag)
s_bf = 1;s_bf += pos if pos.is_a?(Numeric);return q_ag(ag, @bfs+s_bf)
end;def q_ag(ag, s_bf);s_bf = @bfs if s_bf.nil?;return false unless ag.is_a?(Ag) &&
 s_bf.is_a?(Numeric);start_bf = s_bf;@m[start_bf] = [] if @m[start_bf].nil?
@m[start_bf] << ag;if start_bf <= @bfs;ag.trigger(@bfs-start_bf+1)
if ag.is_finished?;@m[start_bf].pop;else;@vv << ag;end;end;return true
end;def bb;frame_rate = Graphics.frame_rate;@last_bf += @tps.to_f / frame_rate.to_f
full_bfs = @last_bf.floor;@last_bf -= full_bfs;bf(full_bfs);end;def bf(bfs = 1)
@bfs += bfs;for nn in @vv;nn.trigger(bfs);@vv.delete(nn) if nn.is_finished?;end
for i in 0...bfs;return if @m[@bfs+i].nil?;for ag in @m[@bfs+i];ag.trigger(bfs-i)
@vv << ag if !ag.is_finished?;end;end;end;def clear;initialize;end;end;class Ab
def initialize;G.non(self);@c = Bitmap.new(2,2);@ae = Viewport.new(@c.rect)
@bb_c = true;end;def ae;return @ae unless @ae.nil?;if !@c.nil?;@ae = Viewport.new(@c.rect)
return @ae;end;@ae = Viewport.new(Rect.new(0,0,32,32));return @ae;end;def rect
return ae.rect;end;def rect=(*mm);mm.flatten!;if mm.size == 1;nm = mm[0]
if nm.is_a?(Rect);ae.rect = nm;return true;end;elsif mm.size == 4
mm.each {|nm| return false unless nm.is_a?(Numeric)};ae.rect = Rect.new(*mm)
return true;end;return false;end;def ox() return ae.ox; end;def oy() return ae.oy
end;def width() return rect.width; end;def height() return rect.height; end
def ox=(val) ae.ox=val if val.is_a?(Numeric); end;def oy=(val) ae.oy=val if val.is_a?(Numeric)
end; def width=(val) rect.width=val if val.is_a?(Numeric) && val >= 1; end
def height=(val) rect.height=val if val.is_a?(Numeric) && val >= 1; end
def x(); return rect.x; end;def x=(val); rect.x=val if val.is_a?(Integer); end
def y(); return rect.y; end;def y=(val); rect.y=val if val.is_a?(Integer); end
def opacity;@opacity = 255 if @opacity.nil?;return @opacity;end;def opacity=(val)
return false unless val.is_a?(Numeric) && val >= 0 && val <= 255;@opacity = val
return true;end;def bitmap;bb if @bb_c && n_u;return @c;end;def bbs?
return @bb_c && n_u;end;def bb_c;return @bb_c;end;def bb_c=(bool)
if bool.is_a?(TrueClass) | bool.is_a?(FalseClass);@bb_c = bool;return true
end;return false;end;def n_u;return true;end;def bb;end;def dispose
@c.dispose unless @c.disposed?;end;end;class Af;attr_accessor :x, :y, :opacity
def initialize(ab);G.non(self);@ab = ab;@opacity = 255;end;def bd() return @bd
end;def bb;unless @bd.is_a?(Sprite) && !@ab.nil?;@bd = Sprite.new(@ab.ae);end
unless @bd.disposed?;return if @ab.nil?;@bd.bitmap = @ab.bitmap;@bd.opacity = @ab.opacity
@bd.update;end;end;def dispose;@bd.dispose unless @bd.nil?;end;end;class Ag
attr_reader :bfs;def initialize;G.non(self);@m = {};@bfs = 0;@length = 1
@tk = false;@vv = [];end;def q_ao(ao, s_bf, length=1);return false unless ao.is_a?(Ao) &&
s_bf.is_a?(Numeric) && length.is_a?(Numeric);start_bf = s_bf;end_bf = length-1 + s_bf
if end_bf > @length-1;@length = end_bf;end;end_bf = start_bf if start_bf > end_bf
@m[start_bf] = [] if @m[start_bf].nil?;@m[start_bf] << [ao, end_bf]
if start_bf <= @bfs and end_bf > @bfs;@vv << [ao, end_bf];end;return true;end
def tk;return @tk unless @tk.nil?;return false;end;def tk=(val)
return false unless val.is_a?(FalseClass) || val.is_a?(TrueClass);@tk = val
return true;end;def length;return @length;end;def length=(number)
return false unless number.is_a?(Numeric);@length = number;return true;end
def trigger(n=1);until n < 1;n -= 1;bf;end;end;def bf;if @bfs >= @length
return unless tk;@bfs = 0;@vv.clear;end;@bfs += 1;for i in 0...@vv.size
nn = @vv[i];unless nn.nil?;nn[0].trigger;@vv.delete_at(i) if nn[1] <= @bfs
end;end;return if @m[@bfs].nil?;for ao in @m[@bfs];ao[0].trigger
@vv << ao if ao[1] > @bfs;end;end;def is_finished?;return true if !tk && @bfs >= @length
return false;end;def dispose;end;end;class Ao;def initialize;G.non(self);end
def trigger;end;end;class Aj < Af;def initialize(window);G.non(self);@window = window
end;def bb;@window.bb;end;def dispose;@window.dispose;end;end;class Ahf < Af
def initialize(ab);super;@window = Window_Base.new(0,0,100,54);@window.width = ab.width + 32
@window.visible = true;end;def bd() return nil; end;def bb;unless @window.disposed?
@window.contents = @ab.bitmap;@window.width = @ab.width + 32;@window.x = @x unless @x.nil?
@window.y = @y unless @y.nil?;end;end;def dispose;@window.dispose unless @window.nil?
end;end;class AkAb < Ab;attr_reader :string, :font;def initialize(string="")
super();self.string = string;@line_distance = 4;@font = @c.font;qq;end;def string=(string)
if string.is_a?(String);@string = string;else;begin;@string = string.to_s;rescue
@string = "Error: Can't convert the nmument to string";end;end;end;def qq;return if @string.nil?
ary = @string.split(/\n/);return if ary.size == 0;ld = 0;ld = @line_distance unless ary.size == 1
width = 0;height = 0;for string in ary;rect = @c.text_size(string);curr_height = rect.height
height = curr_height if curr_height > height;width = rect.width if rect.width > width
end;width + 4;@c = Bitmap.new(width,(height+ld)*ary.size);self.rect.width = @c.width
self.rect.height = @c.height;@c.font = @font;for i in 0...ary.size
@c.draw_text(0,i*(height+@line_distance),width,height,ary[i]);end;end;end
class BAb < Ab;def initialize(b=nil);super();new_b(b);end;def new_b(b=nil)
@c = A.e_c(b);self.width = @c.rect.width - self.x;self.height = @c.rect.height - self.y
end;end;class Am < Ab;def initialize(*mm);super();@changed = false
@ni = true;@h = [];q(*mm);bb;calc_ac;qq;end;def q(*mm);return false if @frozen
mm.flatten!;for ab in mm;if ab.is_a?(Ab);@changed = true;@h << ab;end;end;end
def bb;bc = false;for ab in @h;if ab.bbs?;ab.bb;bc = true;end;end;qq if bc;end
def calc_ac;return false if @h.size == 0;ab = @h[0];width = ab.width + ab.x
height = ab.height + ab.y;for i in 1...@h.size;ab = @h[i];if ab.width + ab.x > width
width = ab.width + ab.x;end;if ab.height + ab.y > height;height = ab.height + ab.y
end;end;if rect.width == width && rect.heigth == height;return false;end
self.rect = rect.x, rect.y, width, height;return true;end;def qq
if self.rect.width == @c.rect.width && self.rect.height == @c.rect.height
@c.clear;else;@c = Bitmap.new(self.rect.width, self.rect.height);end;for ab in @h
rect = Rect.new(ab.ox, ab.oy, ab.width, ab.height);@c.blt(ab.x, ab.y, ab.bitmap, rect, opacity)
end;end;def dispose;if @ni;@h.each {|ab| ab.dispose};end;@c.clear;end;end
class AqAb < Ab;def initialize(number=0);super();self.number = number;@font = @c.font
bb;qq;end;def number;return 0 if @number.nil?;return @number;end;def number=(val)
if val.is_a?(Integer);@next_number = val;else;begin;@next_number = val.to_i
rescue;end;end;end;def bb;super;if @next_number != @number;@number = @next_number
qq;end;end;def qq;return if @number.nil?;rect = @c.text_size(@number.to_s)
@c = Bitmap.new(rect.width, rect.height);self.rect.width = @c.width;self.rect.height = @c.height
@c.font = @font;@c.draw_text(0,0,rect.width,rect.height,@number.to_s,2);end;end
class DacterAb < Ab;attr_writer :wait;def initialize(d_id, f = false);super()
@pos = 0;@aq = 0;@wait = 8;@d_id = d_id;@f = f;set_d(d_id, f);end;def set_d(d_id, f = false)
@c = A.e_d_b(d_id, f);self.width = @c.rect.width/4;self.height = @c.rect.height/4
end;def bb;@aq += 1;if @aq > @wait;@pos += 1;width = @c.width / 4 ;self.ox += width
if @pos >= 4;@pos = 0;self.ox -= @c.width;end;@aq = 0;end;end;def dispose;end
end;class AkAo < Ao;def initialize;G.non(self);end;def trigger;end;end;class BAo < Ao
def initialize(ab, new_b, new_b2);@ab = ab;@new_b = A.e_c(new_b);@new_b2 = A.e_c(new_b2)
@im = true;G.non(self);end;def trigger;if @im;@ab.new_b(@new_b);@im = false;else
@ab.new_b(@new_b2);@im = true;end;end;end;class AmAo < Ao;def initialize;G.non(self)
end;def trigger;end;end;class MAo < Ao;def initialize(object, x=0, y=0);super()
@object = object;@x = x;@y = y;end;def trigger;begin;@object.x += @x;@object.y += @y
rescue;end;end;end;class QAqAo < Ao;def initialize(ab, amount=1);super();@ab = ab
@amount = amount;end;def trigger;if @ab.is_a?(AqAb);if @amount.is_a?(Integer)
@ab.number += @amount;else;@ab.number += 1;end;end;end;end;class Stqo < Ao
def initialize(ag,cab,val);super();@ag = ag;@cab = cab;@val = val;end;def trigger
if @val - 1 <= @cab.number;@ag.tk = false;end;end;end;class GenDotAo < Ao;@@x = 0
@@y = 80;def initialize(x=0,y=80);super();@@x = x;@@y = y;end;def trigger
ig = BAb.new(RPG::Cache.picture("dot.png"));w = Af.new(ig);ao1 = MAo.new(ig,0,-2)
ao2 = MAo.new(ig,0,2);seq = Ag.new;seq.q_ao(ao1,1,5);seq.q_ao(ao2,6,5);seq.tk = true
G.m.q(seq);ig.x = @@x;ig.y = @@y;@@x += 20;@@y += 20 * (@@x / 640);@@x = @@x % 640
end;end;class DisposeAfAo < Ao;def initialize(af);super();@af = af;end;def trigger
@af.dispose;end;end;class AgAo < Ao;def initialize(ag);super();@ag = ag;end
def trigger;end;end;class ExitAo < Ao;def initialize;super();end;def trigger
p "string";exit;end;end;end
Btw. I don't expect you to actually do this XD
I may write some more about the subject later, but currently there's only this exercise as an example ;)
« Last Edit: September 11, 2007, 09:37:34 PM by Zeriab »

******
Revolution is not a bed of roses.
Rep:
Level 91
Project of the Month winner for July 2009
*Screams*

Get it away from me!

Should be an interesting excersize :)
Reminds me when I did some assembly lessons in a comp sci course.

***
Rep:
Level 90
Skilled Scripter, Shitty Mapper, Decent Writer.
Reminds me when I did some assembly lessons in a comp sci course.
Lucky you. I haven't been into a class room for any sort of learning. I'm going to assume it's a good thing I can actually understand some of that though.

EDIT:What the hell is this from?
« Last Edit: September 11, 2007, 11:02:16 PM by Shinami »

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind
I personally think it would be a boring exercise.
I will not tell you what it is. Instead I want you to tell me what it is and what it can be used for.
Try to guess the intention of the author. What purpose has this script? How does it work?
Anyway I have included the file required. Just rename singleton.txt to singleton.rb and place it in a lib directory you have to make.