#include
void url_encode_char(char *va, char ch)
{
/*4005fc: a9bd7bfd stp x29, x30, [sp, #-48]!
400600: 910003fd mov x29, sp
400604: f9000fa0 str x0, [x29, #24] // parameter1
400608: 39005fa1 strb w1, [x29, #23] // parameter2 */
/*40060c: 90000000 adrp x0, 400000 <_init-0x480>
400610: 911e2000 add x0, x0, #0x788 // x0 = 400788
400614: a9400400 ldp x0, x1, [x0] // 16btye
400618: a90207a0 stp x0, x1, [x29, #32] */
char a[] = "0123456789ABCDF";
/*40061c: f9400fa0 ldr x0, [x29, #24] // x0 = parameter1
400620: 528004a1 mov w1, #0x25 // #37
400624: 39000001 strb w1, [x0] */
va[0] = '%';
/*400628: 39405fa0 ldrb w0, [x29, #23] // w0 = parameter2 = 0x61
40062c: 53047c00 lsr w0, w0, #4 // w0 = w0>>4 = 0x6
400630: 12001c00 and w0, w0, #0xff // w0 = (w0>>4)&0xff = 0x6
400634: 12000c01 and w1, w0, #0xf // w1 = w0 & 0xf = 0x6
400638: f9400fa0 ldr x0, [x29, #24] // x0 = parameter1
40063c: 91000400 add x0, x0, #0x1 // x0 = parameter1 + 1
400640: 93407c21 sxtw x1, w1 // x1 = 0x6
400644: 910083a2 add x2, x29, #0x20 // x2 = x29+0x20 = a
400648: 38616841 ldrb w1, [x2, x1] // w1 = a+0x6 = a[6]
40064c: 39000001 strb w1, [x0] // parameter1 + 1 = a[6] */
va[1] = a[(ch>>4)&0x0f];
/*400650: f9400fa0 ldr x0, [x29, #24] // x0 = parameter1
400654: 91000400 add x0, x0, #0x1 // x0 = parameter1+1
400658: 39400000 ldrb w0, [x0] // w0 = [parameter1+1]
40065c: 2a0003e1 mov w1, w0 // w1 = w0
400660: 90000000 adrp x0, 400000 <_init-0x480>
400664: 911e0000 add x0, x0, #0x780
400668: 97ffffa2 bl 4004f0
printf("%c\n", va[1]);
/*40066c: 39405fa0 ldrb w0, [x29, #23] // w0 = parameter2
400670: 12000c01 and w1, w0, #0xf // w1 = w0 & 0xf = 0x1
400674: f9400fa0 ldr x0, [x29, #24] // x0 = parameter1
400678: 91000800 add x0, x0, #0x2 // x0 = parameter2 + 2
40067c: 93407c21 sxtw x1, w1 // x1 = 0x1
400680: 910083a2 add x2, x29, #0x20 // x2 = x29+0x20 = a
400684: 38616841 ldrb w1, [x2, x1] // w1 = a+1 = a[1]
400688: 39000001 strb w1, [x0] // parameter2+2 = a[1]*/
va[2] = a[ch&0xf];
/*40068c: d503201f nop
400690: a8c37bfd ldp x29, x30, [sp], #48
400694: d65f03c0 ret*/
}
int main()
{
/*400698: a9be7bfd stp x29, x30, [sp, #-32]!
40069c: 910003fd mov x29, sp
4006a0: b9001bbf str wzr, [x29, #24]
4006a4: 390073bf strb wzr, [x29, #28]*/
char va[5] = {0};
/*4006a8: 910063a0 add x0, x29, #0x18
4006ac: 52800c21 mov w1, #0x61 // #97
4006b0: 97ffffd3 bl 4005fc
url_encode_char(va, 'a');
/*4006b4: 910063a1 add x1, x29, #0x18
4006b8: 90000000 adrp x0, 400000 <_init-0x480>
4006bc: 911e6000 add x0, x0, #0x798
4006c0: 97ffff8c bl 4004f0
printf("string = %s\n", va);
/*4006c4: 52800000 mov w0, #0x0 // #0
4006c8: a8c27bfd ldp x29, x30, [sp], #32
4006cc: d65f03c0 ret*/
}
// code
static void url_encode_char(char *b, char c)
{
char hex_table[] = "0123456789ABCDF";
b[0] = '%';
b[1] = hex_table[(c >> 4) & 0x0F];
printf("%c\n", b[1]); // 6
b[2] = hex_table[c & 0x0F];
}
int main()
{
char b[5] = {0};
url_encode_char(b, 'a');
printf("main = %s \n", b); // %61
return 0;
}