Skip to content

Commit

Permalink
2001-07-02 Miguel de Icaza <[email protected]>
Browse files Browse the repository at this point in the history
	* dis-cil.c (get_encoded_user_string): Return a string from the
	#US heap. o

	* get.c (get_blob_encoded_size): Implement 23.1.4 decoding.

svn path=/trunk/mono/; revision=47
  • Loading branch information
migueldeicaza committed Jul 2, 2001
1 parent 65225b8 commit 0bf6526
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 2 deletions.
7 changes: 7 additions & 0 deletions mono/dis/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2001-07-02 Miguel de Icaza <[email protected]>

* dis-cil.c (get_encoded_user_string): Return a string from the
#US heap. o

* get.c (get_blob_encoded_size): Implement 23.1.4 decoding.

2001-07-01 Miguel de Icaza <[email protected]>

* dis-cil.c: New file. CIL opcode dissasembler.
Expand Down
33 changes: 31 additions & 2 deletions mono/dis/dis-cil.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdio.h>
#include <wchar.h>
#include "meta.h"
#include "get.h"
#include "dump.h"
#include "dis-cil.h"

Expand Down Expand Up @@ -52,6 +53,30 @@ static opcode_t opcodes [300] = {
#include "mono/cil/opcode.def"
};

/*
* Strings on the US heap are encoded using UTF-16. Poor man's
* UTF-16 to UTF-8. I know its broken, use libunicode later.
*/
static char *
get_encoded_user_string (const char *ptr)
{
char *res;
int len, i, j;

ptr = get_blob_encoded_size (ptr, &len);
res = g_malloc (len + 1);

/*
* I should really use some kind of libunicode here
*/
for (i = 0, j = 0; i < len; j++, i += 2)
res [j] = ptr [i];

res [j] = 0;

return res;
}

void
dissasemble_cil (metadata_t *m, const unsigned char *start, int size)
{
Expand Down Expand Up @@ -125,11 +150,15 @@ dissasemble_cil (metadata_t *m, const unsigned char *start, int size)

case InlineString: {
guint32 token = *(guint32 *) ptr;


char *s = get_encoded_user_string (
mono_metadata_user_string (m, token & 0xffffff));

/*
* See section 23.1.4 on the encoding of the #US heap
*/
fprintf (output, "string-0x%08x", token);
fprintf (output, "\"%s\"", s);
g_free (s);
ptr += 4;
break;
}
Expand Down
30 changes: 30 additions & 0 deletions mono/dis/get.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,4 +566,34 @@ field_flags (guint32 f)
return g_strdup (buffer);
}

/**
* get_blob_encoded_size:
* @ptr: pointer to a blob object
* @size: where we return the size of the object
*
* This decodes a compressed size as described by 23.1.4
*
* Returns: the position to start decoding a blob or user string object
* from.
*/
const char *
get_blob_encoded_size (const char *xptr, int *size)
{
const unsigned char *ptr = xptr;

if ((*ptr & 0x80) == 0){
*size = ptr [0] & 0x7f;
ptr++;
} else if ((*ptr & 0x40) == 0){
*size = ((ptr [0] & 0x3f) << 8) + ptr [1];
ptr += 2;
} else {
*size = ((ptr [0] & 0x1f) << 24) +
(ptr [1] << 16) +
(ptr [2] << 8) +
ptr [3];
ptr += 4;
}

return (char *) ptr;
}
2 changes: 2 additions & 0 deletions mono/dis/get.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ const char *get_ret_type (metadata_t *m, const char *ptr,
const char *get_param (metadata_t *m, const char *ptr,
char **retval);

const char *get_blob_encoded_size (const char *ptr, int *size);

void expand (metadata_tableinfo_t *t, int idx, guint32 *res, int res_size);
1 change: 1 addition & 0 deletions mono/dis/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "util.h"
#include "dump.h"
#include "get.h"
#include "dis-cil.h"

FILE *output;

Expand Down

0 comments on commit 0bf6526

Please sign in to comment.