Please login or register.

Login with username, password and session length
Pages: 1 [2] 3 4
I'ma Firin Mah Lazorz!
RandMuadDib [Posts: 381]
  • View Profile
  • share
  • [June 29, 2011, 02:24:43 AM]
Re: (App) MassHexASM: Encode directly to little endian
« Reply #20 on: June 29, 2011, 02:24:43 AM »
i'm sorry every time i see 'armips' it always looks like 'armpits' to me o.O

I will show you the power of SARDIIIIINES!!!!
SaGa Frontier Hacker
Pickle Girl Fanboy [Posts: 1482]
  • View Profile
  • Bio Research Lab
  • share
  • [June 29, 2011, 09:21:40 PM]
Re: (App) MassHexASM: Encode directly to little endian
« Reply #21 on: June 29, 2011, 09:21:40 PM »
I don't care one way or another, but I felt obligated to give you Gemini's opinion on this, because he has years of experience with this.
Bad code, beware! The NOPs are coming to eat you!
formerdeathcorps [Posts: 1322]
  • View Profile
  • share
  • [November 02, 2011, 06:27:41 AM]
Re: (App) MassHexASM: Encode directly to little endian
« Reply #22 on: November 02, 2011, 06:27:41 AM »
Two problems I'm noticing.

sllv/jalr/srav does not convert from hex to ASM and vice-versa.
jr r31 sometimes is translated as jr r1 if you also require a non-zero amount of padding on the generated hex.  I'm not sure if this is just me typing jr 31, though.
« Last Edit: November 02, 2011, 07:14:11 AM by formerdeathcorps »
The destruction of the will is the rape of the mind.
The dogmas of every era are nothing but the fantasies of those in power; their dreams are our waking nightmares.
Glain [Posts: 479]
  • View Profile
  • share
  • [November 02, 2011, 12:27:02 PM]
Re: (App) MassHexASM: Encode directly to little endian
« Reply #23 on: November 02, 2011, 12:27:02 PM »
I simply missed srav and jalr, so I'll have to add those in. As for sllv, not sure what I'm missing; I see the program producing output for that command, at least if it's got three registers, e.g. sllv r2,r3,r4. That command would shift r3 left r4 bits and store the result in r2?

jr 31 does seem to produce jr r1 if decoded, so it might just be that typo; I'll be on the lookout to see if jr r31 produces the wrong hex in certain situations.
Bad code, beware! The NOPs are coming to eat you!
formerdeathcorps [Posts: 1322]
  • View Profile
  • share
  • [November 28, 2011, 04:46:40 AM]
Re: (App) MassHexASM: Encode directly to little endian
« Reply #24 on: November 28, 2011, 04:46:40 AM »
sllv is right, I found no more errors there.

Labels still don't work though.  If I try

bne r3, r0, PLACE
....
PLACE:

it will sometimes fail.  If PLACE is separated at least 5 commands from the branch command, it is almost always an undercount.
« Last Edit: November 28, 2011, 04:47:24 AM by formerdeathcorps »
The destruction of the will is the rape of the mind.
The dogmas of every era are nothing but the fantasies of those in power; their dreams are our waking nightmares.
Glain [Posts: 479]
  • View Profile
  • share
  • [November 28, 2011, 06:09:43 AM]
Re: (App) MassHexASM: Encode directly to little endian
« Reply #25 on: November 28, 2011, 06:09:43 AM »
I made a few attempts to reproduce that, and couldn't; can you give some input that will result in incorrect hex? From my understanding, the number encoded in the beq/bne instruction is the number of commands to jump over, thus:

bne r3,r0,PLACE
nop
nop
nop
nop
nop
nop
PLACE: nop

would result in the bne being encoded as (little endian) 06006014 (jump over 6 commands).

(I suppose the first command after the beq/bne is actually the branch delay slot so it actually isn't "jumped over" at all, but it's still 6 commands between the bne and the label, exclusive.)
Bad code, beware! The NOPs are coming to eat you!
formerdeathcorps [Posts: 1322]
  • View Profile
  • share
  • [November 28, 2011, 06:18:16 AM]
Re: (App) MassHexASM: Encode directly to little endian
« Reply #26 on: November 28, 2011, 06:18:16 AM »
No, 06 is correct.

The problem is this.  If you do:

bne r3, r0, PLACE
nop
nop
nop
SPOT: nop
nop
nop
nop
nop
PLACE: nop

you'll get 7 instead of 8 because you skip the command with SPOT:
« Last Edit: November 28, 2011, 06:19:10 AM by formerdeathcorps »
The destruction of the will is the rape of the mind.
The dogmas of every era are nothing but the fantasies of those in power; their dreams are our waking nightmares.
Glain [Posts: 479]
  • View Profile
  • share
  • [November 28, 2011, 05:57:17 PM]
Re: (App) MassHexASM: Encode directly to little endian
« Reply #27 on: November 28, 2011, 05:57:17 PM »
Ah, nice find. It was getting the label address wrong, because it wasn't incrementing the address of the current line if it ran into a label, without regard to the fact that a command could be on the same line as the label, and it would need to increment the address in that case.

I fixed that problem and added in support for the missing commands you mentioned as well as a few others. I've attached a new version (v7) and added a changelog entry in the original post of this thread. Let me know if you find any more bugs or what have you.
Bad code, beware! The NOPs are coming to eat you!
formerdeathcorps [Posts: 1322]
  • View Profile
  • share
  • [January 16, 2012, 12:48:11 AM]
Re: (App) MassHexASM: Encode directly to little endian
« Reply #28 on: January 16, 2012, 12:48:11 AM »
Another small issue.

ori / andi are never signed commands because they are logical bitwise commands.  It's actually quite odd to read
lui r1, 0x8005
ori r1, r0, 0xF874 (just as a random example)

as

lui r1, 0x8005
ori r1, r0, -0x078C

since what I care to find is the address (5F874), not a meaningless (or in this case, wrong) arithmetic/logical operation.

Also, a feature request.  It's annoying in a long routine to find the address of a command buried deep in the routine.  Would it be possible to use the "Comment" box to display the starting and ending address of a highlighted section?
« Last Edit: January 16, 2012, 03:57:10 AM by formerdeathcorps »
The destruction of the will is the rape of the mind.
The dogmas of every era are nothing but the fantasies of those in power; their dreams are our waking nightmares.
Glain [Posts: 479]
  • View Profile
  • share
  • [January 16, 2012, 05:50:21 AM]
Re: (App) MassHexASM: Encode directly to little endian
« Reply #29 on: January 16, 2012, 05:50:21 AM »
I never even noticed that it was displaying signed numbers for and/or operations. We'll definitely want the unsigned numbers there... I'm adding in some code to differentiate some of those commands. How about this?

Unsigned: andi, ori, xori, sltiu
Signed: addi, addiu, slti
(I'm pretty sure sltiu actually treats the immediate as unsigned, unlike addiu).

You have a good idea there about displaying the addresses of the commands, but I don't like using the Messages box to do it. I was thinking of displaying them to the left of the assembly textbox, but I'm not sure how I'd make that work with scrolling. Maybe I could display

[address] command
[address] command

in the textbox itself, and just ignore everything between brackets when encoding, and have a flag to decide whether you want to see the addresses when decoding. Something like that.
☯☯☯☯
FFMaster [Posts: 2499]
  • View Profile
  • share
  • [January 16, 2012, 07:15:08 AM]
Re: (App) MassHexASM: Encode directly to little endian
« Reply #30 on: January 16, 2012, 07:15:08 AM »
I would like that a lot. It would help me, at least.

☢ CAUTION CAUTION ☢ CAUTION CAUTION ☢
Glain [Posts: 479]
  • View Profile
  • share
  • [January 17, 2012, 04:05:51 AM]
Re: (App) MassHexASM: Encode directly to little endian
« Reply #31 on: January 17, 2012, 04:05:51 AM »
Here's what I've got now. Does this look about right? I'm just ignoring anything between brackets.

☯☯☯☯
FFMaster [Posts: 2499]
  • View Profile
  • share
  • [January 17, 2012, 05:29:20 AM]
Re: (App) MassHexASM: Encode directly to little endian
« Reply #32 on: January 17, 2012, 05:29:20 AM »
Yeah, that looks good.

If I had say, these 3 lines of code:

lui r2,0x8019
addiu r2,r2,0x0001
nop

and copy/pasted it into the left box, would the addresses automatically be added in with Show Addresses on?

☢ CAUTION CAUTION ☢ CAUTION CAUTION ☢
Glain [Posts: 479]
  • View Profile
  • share
  • [January 17, 2012, 02:20:24 PM]
Re: (App) MassHexASM: Encode directly to little endian
« Reply #33 on: January 17, 2012, 02:20:24 PM »
I don't think I can add the addresses unless I'm going through an encode/decode process... I have to differentiate blank lines, comments, labels, etc, from ASM commands; only the commands get addresses. Plus I don't want to trap the paste action, or typing; it can get a bit messy. I can make Encode show the addresses on the left though.
Glain [Posts: 479]
  • View Profile
  • share
  • [January 26, 2012, 01:02:22 AM]
Re: (App) MassHexASM: Encode directly to little endian (v8)
« Reply #34 on: January 26, 2012, 01:02:22 AM »
All right, I've released a new version and updated the original post. It should be decoding immediates correctly for all the commands we mentioned, should be able to show addresses on encode/decode and I made a few other changes.
Choto [Posts: 819]
  • View Profile
  • share
  • [February 09, 2012, 12:29:14 PM]
Re: (App) MassHexASM: Encode directly to little endian
« Reply #35 on: February 09, 2012, 12:29:14 PM »
Hey Glain, I'm getting a problem with beq commands, not sure if its me or MHA

I tried encoding:

beq r4, r0, 0x0018ea80

and get

A9638010

I then press decode to check if its correct, and it turns into

beq r4,r0,0x00018ea8

The other address I'm trying goes from

beq r4,r0,0x0018ea24 to
beq r4,r0,0x00018ea4,

which is a little different because it doesn't just shift everything over 1 bit(?) like the previous example.

I wasn't sure if this was the same problem as you guys described before. There were 2 cases of it, one when jumping from 0x0018ea14 to 0x0018ea24 and when jumping from 0x0018ea20 to 0x0018ea80

whachu tink?

P.S. I'm using MasshexASM 8.0
« Last Edit: February 09, 2012, 01:04:11 PM by Choto »
Glain [Posts: 479]
  • View Profile
  • share
  • [February 09, 2012, 01:51:44 PM]
Re: (App) MassHexASM: Encode directly to little endian
« Reply #36 on: February 09, 2012, 01:51:44 PM »
I can test this later, but one thing about the beq/bne instructions is that they're actually encoded as branches over a certain number of statements, as opposed to branching to an address... so the address it displays is very dependent on the "starting address" box and the position in the code it's in. If I have:

0x0018ea6c: beq r4,r0,0x0018ea80
0x0018ea70: (branch delay slot)
0x0018ea74: ...
0x0018ea78: ...
0x0018ea7c: ...
0x0018ea80: (branch target)

The final instruction is basically just "if (r4 == r0), jump over 4 lines (but still run the one in the branch delay slot first)". In other words, the target address isn't in the encoded instruction at all, so if you encode it in different places in the ASM or use different starting addresses, you'll actually get different results. If I decode that example command with MHA and don't specify a starting address, it'll assume a starting address of 0 and it'll come out as:

beq r4,r0,0x00000014

Something to keep in mind with those statements.

EDIT: Oh, and there's also a limit to how far you can branch with the conditional branches (beq,bne,et.al.). You can only go so far (I think 65535 statements?). If you need to go further, use a shorter conditional branch to another place in your code, then use a j statement to get there (which actually encodes an address). In other words, instead of doing this...

beq r4,r0,(really far away address)        # Too far for beq to go... this won't work and can't encode properly.
nop

Use this pattern:

beq r4,r0,(JUMP)
nop
j (PAST_JUMP)
nop
(JUMP):
j (really far away address)                  # j is awesome and can go anywhere (as long as it's a valid code address, i.e. a multiple of 4).
nop
(PAST_JUMP):
(rest of routine)
« Last Edit: February 09, 2012, 02:23:14 PM by Glain »
Choto [Posts: 819]
  • View Profile
  • share
  • [February 09, 2012, 02:32:28 PM]
Re: (App) MassHexASM: Encode directly to little endian
« Reply #37 on: February 09, 2012, 02:32:28 PM »
Ah ha, I see. I specified the starting address and it worked like a charm, thanks for the explanation!
SaGa Frontier Hacker
Pickle Girl Fanboy [Posts: 1482]
  • View Profile
  • Bio Research Lab
  • share
  • [March 18, 2012, 10:34:11 PM]
Re: (App) MassHexASM: Encode directly to little endian
« Reply #38 on: March 18, 2012, 10:34:11 PM »
Testing Java version on Linux Mint 10, 32-bit, Gnome dot dot dot

Fails to load.  I will update my Java and try again tomorrow.
Glain [Posts: 479]
  • View Profile
  • share
  • [March 19, 2012, 12:43:14 AM]
Re: (App) MassHexASM: Encode directly to little endian
« Reply #39 on: March 19, 2012, 12:43:14 AM »
If you're getting the "Unsupported major.minor version" error, then it is indeed because you need to update Java. I compiled with Java 1.7, which, in retrospect, seems to be pretty recent, and it seems you need Java 1.7 to run it. Basically if "java -version" gives you anything before 1.7, then you need to update.

I just tried this on a Linux (Ubuntu) laptop and got it to work after finally managing to install Java 1.7 (I was getting the "Unsupported major.minor version" error before then). For some reason, apt-get didn't work for me, so I had to follow these instructions (top answer). I downloaded the JDK, but I imagine the same instructions would work for the JRE.
Pages: 1 [2] 3 4